2 #include "tilda-terminal.h"
3 #include "tilda-config.h"
4 #include "tilda-terminal-dbus-glue.h"
8 #define DINGUS1 "(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?"
9 #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_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"]"
24 } TildaDynamicTitleActions;
31 } TildaScrollbarPositions;
36 tilda_terminal_dbus_register_object (TildaTerminal *tt)
39 debug_assert (TILDA_IS_TERMINAL(tt));
41 TildaWindow *parent_window = TILDA_WINDOW(tt->parent_window);
44 // Register this object with DBus
45 object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d/Terminal%d",
46 parent_window->number, tt->number);
47 dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tt));
52 tilda_terminal_run_command (TildaTerminal *self, gchar *command, GError **error)
55 debug_assert (TILDA_IS_TERMINAL(self));
57 vte_terminal_feed_child (VTE_TERMINAL(self->vte_term), command, -1);
58 vte_terminal_feed_child (VTE_TERMINAL(self->vte_term), "\n", -1);
64 tilda_terminal_close (TildaTerminal *self, GError **error)
67 debug_assert (TILDA_IS_TERMINAL(self));
69 TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
71 tilda_window_remove_terminal (parent_window, self->number);
77 * Start the current tt->shell in the given TildaTerminal
78 * NOTE: this will kill whatever is running in the terminal,
79 * NOTE: and run the current tt->shell instead :)
80 * Return: TRUE if ok, FALSE otherwise
83 tilda_terminal_start_shell (TildaTerminal *tt)
86 debug_assert (TILDA_IS_TERMINAL(tt));
93 /* Launch a custom command if tt->shell is set (not NULL) */
96 /* Try to parse the user's custom command */
97 ret = g_shell_parse_argv (tt->shell, &argc, &argv, &error);
101 g_printerr (_("Problem parsing custom command: %s\n"), error->message);
102 g_printerr (_("Launching default shell instead\n"));
104 g_error_free (error);
105 goto launch_default_shell;
108 /* Try to start the user's custom command */
109 ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
110 argv[0], /* Command */
111 argv, /* Arg Vector */
112 NULL, /* Env Vector */
113 tt->working_directory, /* Start directory */
114 TRUE, /* Add to lastlog */
115 TRUE, /* Add to utmp */
116 TRUE); /* Add to wtmp */
120 /* Check for error */
123 g_printerr (_("Unable to launch custom command: %s\n"), tt->shell);
124 g_printerr (_("Launching default shell instead\n"));
126 goto launch_default_shell;
129 return TRUE; /* SUCCESS: the early way out */
132 launch_default_shell:
134 ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
135 NULL, /* Command -- VTE will figure it out */
136 NULL, /* Arg Vector */
137 NULL, /* Env Vector */
138 tt->working_directory, /* Start Directory */
139 TRUE, /* Add to lastlog */
140 TRUE, /* Add to utmp */
141 TRUE);/* Add to wtmp */
145 g_printerr (_("Unable to launch default shell\n"));
153 * Called when the child process running in the VteTerminal exits.
156 tilda_terminal_child_exited_cb (GtkWidget *widget, gpointer data)
159 debug_assert (GTK_IS_WIDGET(widget));
160 debug_assert (TILDA_IS_TERMINAL(data));
162 TildaTerminal *self = TILDA_TERMINAL(data);
164 /* Check the user's preference for what to do when the child terminal
165 * is closed. Take the appropriate action */
166 switch (self->exit_action)
169 tilda_window_remove_terminal (TILDA_WINDOW(self->parent_window), self->number);
171 case RESTART_COMMAND:
172 vte_terminal_feed (VTE_TERMINAL(self->vte_term), "\r\n\r\n", 4);
173 tilda_terminal_start_shell (self);
183 * Called when the child window title changes. Determines if a new
184 * title needs to be put into the notebook's tab label.
187 tilda_terminal_window_title_changed_cb (GtkWidget *widget, gpointer data)
190 debug_assert (GTK_IS_WIDGET(widget));
191 debug_assert (TILDA_IS_TERMINAL(data));
193 TildaTerminal *self = TILDA_TERMINAL(data);
194 TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
196 const gchar *vte_title;
199 label = gtk_notebook_get_tab_label (GTK_NOTEBOOK(parent_window->notebook), self->hbox);
201 /* If we aren't using a dynamic title -- NOT_DISPLAYED -- then just
202 * set it to the static title and exit */
203 if (!self->dynamic_title)
205 gtk_label_set_text (GTK_LABEL(label), self->title);
209 /* Get the title from VTE */
210 vte_title = vte_terminal_get_window_title (VTE_TERMINAL (widget));
212 /* Take the appropriate action */
213 switch (self->dynamic_title)
215 case REPLACE_INITIAL:
216 new_title = g_strdup (vte_title);
220 new_title = g_strdup_printf ("%s - %s", vte_title, self->title);
224 new_title = g_strdup_printf ("%s - %s", self->title, vte_title);
228 debug_printf ("ERROR: Bad value of self->dynamic_title\n");
230 new_title = g_strdup(self->title);
234 gtk_label_set_text (GTK_LABEL(label), new_title);
239 * Gets called whenever there is a button-press event in the VteTerminal. It
240 * is used to open the user's web browser, for example.
243 tilda_terminal_button_press_cb (GtkWidget *widget,
244 GdkEventButton *event,
248 debug_assert (GTK_IS_WIDGET(widget));
249 debug_assert (TILDA_IS_TERMINAL(data));
250 debug_printf ("event->button = %d\n", event->button);
252 GError *error = NULL;
253 TildaTerminal *self = TILDA_TERMINAL(data);
254 VteTerminal *terminal = VTE_TERMINAL(self->vte_term);
255 gint tag, xpad, ypad;
256 gchar *match, *cmd, *web_browser_cmd;
257 gboolean ret = FALSE;
259 switch (event->button)
261 case 3: /* Right Click */
262 // FIXME: need to add this
263 //popup_menu (tt->tw, tt);
264 g_print ("FIXME: popup_menu() here\n");
267 case 2: /* Middle Click */
270 case 1: /* Left Click */
271 vte_terminal_get_padding (terminal, &xpad, &ypad);
272 match = vte_terminal_match_check (terminal,
273 (event->x - ypad) / terminal->char_width,
274 (event->y - ypad) / terminal->char_height,
277 /* Check if we can launch a web browser, and do so if possible */
278 if ((event->state & GDK_CONTROL_MASK) && match != NULL)
280 web_browser_cmd = g_strescape (self->web_browser, NULL);
281 cmd = g_strdup_printf ("%s %s", web_browser_cmd, match);
283 debug_printf ("Got a Ctrl+Left-Click -- match: '%s' tag: %d\n", match, tag);
284 debug_printf ("Launching command: '%s'\n", cmd);
286 ret = g_spawn_command_line_async(cmd, &error);
288 /* Check that the command launched */
291 g_printerr (_("Failed to launch web browser command: `%s'\n"), cmd);
292 g_printerr (_("Error message: %s\n"), error->message);
295 /* Free allocated memory */
296 g_free (web_browser_cmd);
300 /* Always free match if it is non NULL */
312 * Set the given TildaTerminal to the appropriate transparency level
313 * based on the self->transparency_percent member. */
315 tilda_terminal_set_transparent (TildaTerminal *self)
318 debug_assert (TILDA_IS_TERMINAL(self));
320 TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
323 /* Convert the transparency to VTE's format */
324 temp = ((gdouble) self->transparency_percent) / 100.0;
326 if (self->transparency_percent > 0)
328 vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), temp);
329 vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), (1.0 - temp) * 0xffff);
331 /* Use fake transparency if necessary */
332 vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term),
333 !parent_window->have_real_transparency);
337 /* Turn off transparency */
338 vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), 0);
339 vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), 0xffff);
340 vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term), FALSE);
344 * Set the scrollbar position of the given TildaTerminal to
345 * the value in self->scrollbar_position.
348 tilda_terminal_set_scrollbar_position (TildaTerminal *self)
351 debug_assert (TILDA_IS_TERMINAL(self));
353 switch (self->scrollbar_position)
356 gtk_box_reorder_child (GTK_BOX(self->hbox), self->scrollbar, 0);
357 gtk_widget_show (self->scrollbar);
361 gtk_box_reorder_child (GTK_BOX(self->hbox), self->scrollbar, 1);
362 gtk_widget_show (self->scrollbar);
366 debug_printf ("ERROR: Bad scrollbar position\n");
368 gtk_widget_hide (self->scrollbar);
373 /*******************************************************************************
374 * All configuration subsystem code is below
375 ******************************************************************************/
378 * Lookup a setting in the config file for this TildaTerminal.
380 * The returned string MUST be g_strdup()'d if you want to actually use
381 * it as a value. It is owned by the config system. You MUST NOT g_free() it.
384 tilda_terminal_lookup_from_config (TildaTerminal *self, const gchar key[])
387 debug_assert (TILDA_IS_TERMINAL(self));
388 debug_assert (key != NULL);
390 GError *error = NULL;
394 /* Do the bottom-most lookup */
395 group_name = g_strdup_printf ("Window%d/Terminal%d",
396 TILDA_WINDOW(self->parent_window)->number,
398 value = g_key_file_get_string (config_userprefs, group_name, key, &error);
404 g_clear_error (&error);
406 /* Do the next highest lookup */
407 group_name = g_strdup_printf ("Window%d",
408 TILDA_WINDOW(self->parent_window)->number);
409 value = g_key_file_get_string (config_userprefs, group_name, key, &error);
415 g_clear_error (&error);
417 /* Do the global lookup */
418 value = g_key_file_get_string (config_userprefs, "Global", key, &error);
423 g_clear_error (&error);
425 /* Look in the defaults */
426 if (!g_hash_table_lookup_extended (config_defaults, key, NULL, &value))
428 /* If this happened, the developers forgot to set the default for
429 * a key they added. Please email them. */
430 g_critical ("Error: unable to find the default for key=%s\n", key);
434 /* Return the default key */
439 * Set one of TildaTerminal's integer properties from the config file or defaults.
442 tilda_terminal_config_int_property (TildaTerminal *self, const gchar *property)
445 debug_assert (TILDA_IS_TERMINAL(self));
446 debug_assert (property != NULL);
449 gchar *config_value_raw;
451 config_value_raw = tilda_terminal_lookup_from_config (self, property);
452 config_value = atoi (config_value_raw);
453 g_object_set (G_OBJECT(self), property, config_value, NULL);
457 tilda_terminal_config_enum_property (TildaTerminal *self, const gchar *property)
460 debug_assert (TILDA_IS_TERMINAL(self));
461 debug_assert (property != NULL);
464 gchar *config_value_raw;
466 /* Copy, then strip spaces off of the string from the config */
467 config_value_raw = g_strstrip (g_strdup (tilda_terminal_lookup_from_config (self, property)));
471 /* Just try all of the possible enums */
472 if (g_ascii_strcasecmp (config_value_raw, "LEFT") == 0)
474 else if (g_ascii_strcasecmp (config_value_raw, "RIGHT") == 0)
475 config_value = RIGHT;
476 else if (g_ascii_strcasecmp (config_value_raw, "HOLD-OPEN") == 0)
477 config_value = HOLD_OPEN;
478 else if (g_ascii_strcasecmp (config_value_raw, "RESTART-COMMAND") == 0)
479 config_value = RESTART_COMMAND;
480 else if (g_ascii_strcasecmp (config_value_raw, "EXIT") == 0)
482 else if (g_ascii_strcasecmp (config_value_raw, "VTE-ERASE-AUTO") == 0)
483 config_value = VTE_ERASE_AUTO;
484 else if (g_ascii_strcasecmp (config_value_raw, "VTE-ERASE-ASCII-BACKSPACE") == 0)
485 config_value = VTE_ERASE_ASCII_BACKSPACE;
486 else if (g_ascii_strcasecmp (config_value_raw, "VTE-ERASE-ASCII-DELETE") == 0)
487 config_value = VTE_ERASE_ASCII_DELETE;
488 else if (g_ascii_strcasecmp (config_value_raw, "VTE-ERASE-DELETE-SEQUENCE") == 0)
489 config_value = VTE_ERASE_DELETE_SEQUENCE;
490 else if (g_ascii_strcasecmp (config_value_raw, "NOT-DISPLAYED") == 0)
491 config_value = NOT_DISPLAYED;
492 else if (g_ascii_strcasecmp (config_value_raw, "AFTER-INITIAL") == 0)
493 config_value = AFTER_INITIAL;
494 else if (g_ascii_strcasecmp (config_value_raw, "BEFORE-INITIAL") == 0)
495 config_value = BEFORE_INITIAL;
496 else if (g_ascii_strcasecmp (config_value_raw, "REPLACE-INITIAL") == 0)
497 config_value = REPLACE_INITIAL;
500 g_critical ("Unable to parse: '%s' as an enum\n", config_value_raw);
502 /* Use the default -- which I sure hope is valid (famous last words) */
503 config_value_raw = g_hash_table_lookup (config_defaults, property);
507 /* Free the value from the config system */
508 g_free (config_value_raw);
510 g_object_set (G_OBJECT(self), property, config_value, NULL);
514 tilda_terminal_config_string_property (TildaTerminal *self, const gchar *property)
517 debug_assert (TILDA_IS_TERMINAL(self));
518 debug_assert (property != NULL);
520 gchar *config_value_raw;
522 config_value_raw = tilda_terminal_lookup_from_config (self, property);
524 /* The property system g_strdup()s strings for us! */
525 g_object_set (G_OBJECT(self), property, config_value_raw, NULL);
529 tilda_terminal_config_boolean_property (TildaTerminal *self, const gchar *property)
532 debug_assert (TILDA_IS_TERMINAL(self));
533 debug_assert (property != NULL);
535 gboolean config_value;
536 gchar *config_value_raw;
538 config_value_raw = tilda_terminal_lookup_from_config (self, property);
542 if (g_ascii_strcasecmp (config_value_raw, "true") == 0)
544 else if (g_ascii_strcasecmp (config_value_raw, "false") == 0)
545 config_value = FALSE;
548 g_critical ("Unable to parse: '%s' as a boolean\n", config_value_raw);
550 /* Use the default -- which I sure hope is valid (famous last words) */
551 config_value_raw = g_hash_table_lookup (config_defaults, property);
555 g_object_set (G_OBJECT(self), property, config_value, NULL);
559 /*******************************************************************************
560 * All GObject stuff is below. You probably don't need to change this...
561 ******************************************************************************/
563 static GObjectClass *parent_class = NULL;
565 enum tilda_terminal_properties {
566 TILDA_TERMINAL_NUMBER = 1,
567 TILDA_TERMINAL_PARENT_WINDOW,
569 /* All non-constructor-only properties */
570 TILDA_TERMINAL_BACKGROUND_IMAGE,
571 TILDA_TERMINAL_SHELL,
573 TILDA_TERMINAL_TITLE,
574 TILDA_TERMINAL_WORKING_DIRECTORY,
575 TILDA_TERMINAL_WEB_BROWSER,
577 TILDA_TERMINAL_SCROLLBACK_LINES,
578 TILDA_TERMINAL_TRANSPARENCY_PERCENT,
580 TILDA_TERMINAL_BACKSPACE_BINDING,
581 TILDA_TERMINAL_DELETE_BINDING,
582 TILDA_TERMINAL_DYNAMIC_TITLE,
583 TILDA_TERMINAL_EXIT_ACTION,
584 TILDA_TERMINAL_SCROLLBAR_POSITION,
586 TILDA_TERMINAL_SCROLL_BACKGROUND,
587 TILDA_TERMINAL_SCROLL_ON_OUTPUT,
588 TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
589 TILDA_TERMINAL_ANTIALIASED,
590 TILDA_TERMINAL_ALLOW_BOLD_TEXT,
591 TILDA_TERMINAL_CURSOR_BLINKS,
592 TILDA_TERMINAL_AUDIBLE_BELL,
593 TILDA_TERMINAL_VISIBLE_BELL,
594 TILDA_TERMINAL_DOUBLE_BUFFERED,
595 TILDA_TERMINAL_MOUSE_AUTOHIDE,
599 tilda_terminal_instance_init (GTypeInstance *instance,
604 TildaTerminal *self = (TildaTerminal *) instance;
606 /* Initialize instance members and allocate any necessary memory here.
607 * NOTE: any constructor-time values will be set later. */
608 self->dispose_has_run = FALSE;
611 self->vte_term = vte_terminal_new ();
612 self->scrollbar = gtk_vscrollbar_new (VTE_TERMINAL(self->vte_term)->adjustment);
613 self->hbox = gtk_hbox_new (FALSE, 0);
617 tilda_terminal_set_property (GObject *object,
622 TildaTerminal *self = (TildaTerminal *) object;
624 switch (property_id) {
626 case TILDA_TERMINAL_NUMBER:
627 self->number = g_value_get_int (value);
628 debug_printf ("terminal number: %d\n", self->number);
631 case TILDA_TERMINAL_PARENT_WINDOW:
632 self->parent_window = g_value_get_pointer (value);
633 debug_printf ("terminal parent window: 0x%x\n", self->parent_window);
636 case TILDA_TERMINAL_BACKGROUND_IMAGE:
637 g_free (self->background_image);
638 self->background_image = g_value_dup_string (value);
639 vte_terminal_set_background_image_file (VTE_TERMINAL(self->vte_term), self->background_image);
640 debug_printf ("terminal back img: %s\n", self->background_image);
643 case TILDA_TERMINAL_SHELL:
644 g_free (self->shell);
645 self->shell = g_value_dup_string (value);
646 tilda_terminal_start_shell (self);
647 debug_printf ("terminal shell: %s\n", self->shell);
650 case TILDA_TERMINAL_FONT:
652 self->font = g_value_dup_string (value);
653 vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
656 debug_printf ("terminal font: %s\n", self->font);
659 case TILDA_TERMINAL_TITLE:
660 g_free (self->title);
661 self->title = g_value_dup_string (value);
662 debug_printf ("terminal title: %s\n", self->title);
665 case TILDA_TERMINAL_WORKING_DIRECTORY:
666 g_free (self->working_directory);
667 self->working_directory = g_value_dup_string (value);
668 debug_printf ("terminal wrk dir: %s\n", self->working_directory);
671 case TILDA_TERMINAL_WEB_BROWSER:
672 g_free (self->web_browser);
673 self->web_browser = g_value_dup_string (value);
674 debug_printf ("terminal web browser: %s\n", self->web_browser);
677 case TILDA_TERMINAL_SCROLLBACK_LINES:
678 self->scrollback_lines = g_value_get_int (value);
679 vte_terminal_set_scrollback_lines (VTE_TERMINAL(self->vte_term), self->scrollback_lines);
680 debug_printf ("terminal scrollback lines: %d\n", self->scrollback_lines);
683 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
684 self->transparency_percent = g_value_get_int (value);
685 tilda_terminal_set_transparent (self);
686 debug_printf ("terminal transp percent: %d\n", self->transparency_percent);
689 case TILDA_TERMINAL_BACKSPACE_BINDING:
690 self->backspace_binding = g_value_get_int (value);
691 vte_terminal_set_backspace_binding (VTE_TERMINAL(self->vte_term), self->backspace_binding);
692 debug_printf ("terminal backspace key: %d\n", self->backspace_binding);
695 case TILDA_TERMINAL_DELETE_BINDING:
696 self->delete_binding = g_value_get_int (value);
697 vte_terminal_set_delete_binding (VTE_TERMINAL(self->vte_term), self->delete_binding);
698 debug_printf ("terminal delete key: %d\n", self->delete_binding);
701 case TILDA_TERMINAL_DYNAMIC_TITLE:
702 self->dynamic_title = g_value_get_int (value);
703 debug_printf ("terminal dynamic title: %d\n", self->dynamic_title);
706 case TILDA_TERMINAL_EXIT_ACTION:
707 self->exit_action = g_value_get_int (value);
708 debug_printf ("terminal exit action: %d\n", self->exit_action);
711 case TILDA_TERMINAL_SCROLLBAR_POSITION:
712 self->scrollbar_position = g_value_get_int (value);
713 tilda_terminal_set_scrollbar_position (self);
714 debug_printf ("terminal scrollbar position: %d\n", self->scrollbar_position);
717 case TILDA_TERMINAL_SCROLL_BACKGROUND:
718 self->scroll_background = g_value_get_boolean (value);
719 vte_terminal_set_scroll_background (VTE_TERMINAL(self->vte_term), self->scroll_background);
720 debug_printf ("terminal scroll background: %d\n", self->scroll_background);
723 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
724 self->scroll_on_output = g_value_get_boolean (value);
725 vte_terminal_set_scroll_on_output (VTE_TERMINAL(self->vte_term), self->scroll_on_output);
726 debug_printf ("terminal scroll on output: %d\n", self->scroll_on_output);
729 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
730 self->scroll_on_keystroke = g_value_get_boolean (value);
731 vte_terminal_set_scroll_on_keystroke (VTE_TERMINAL(self->vte_term), self->scroll_on_keystroke);
732 debug_printf ("terminal scroll on keystroke: %d\n", self->scroll_on_keystroke);
735 case TILDA_TERMINAL_ANTIALIASED:
736 self->antialiased = g_value_get_boolean (value);
737 vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
740 debug_printf ("terminal antialiased: %d\n", self->antialiased);
743 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
744 self->allow_bold_text = g_value_get_boolean (value);
745 vte_terminal_set_allow_bold (VTE_TERMINAL(self->vte_term), self->allow_bold_text);
746 debug_printf ("terminal allow bold text: %d\n", self->allow_bold_text);
749 case TILDA_TERMINAL_CURSOR_BLINKS:
750 self->cursor_blinks = g_value_get_boolean (value);
751 vte_terminal_set_cursor_blinks (VTE_TERMINAL(self->vte_term), self->cursor_blinks);
752 debug_printf ("terminal cursor blinks: %d\n", self->cursor_blinks);
755 case TILDA_TERMINAL_AUDIBLE_BELL:
756 self->audible_bell = g_value_get_boolean (value);
757 vte_terminal_set_audible_bell (VTE_TERMINAL(self->vte_term), self->audible_bell);
758 debug_printf ("terminal audible bell: %d\n", self->audible_bell);
761 case TILDA_TERMINAL_VISIBLE_BELL:
762 self->visible_bell = g_value_get_boolean (value);
763 vte_terminal_set_visible_bell (VTE_TERMINAL(self->vte_term), self->visible_bell);
764 debug_printf ("terminal visible bell: %d\n", self->visible_bell);
767 case TILDA_TERMINAL_DOUBLE_BUFFERED:
768 self->double_buffered = g_value_get_boolean (value);
769 gtk_widget_set_double_buffered (GTK_WIDGET(self->vte_term), self->double_buffered);
770 debug_printf ("terminal double buffered: %d\n", self->double_buffered);
773 case TILDA_TERMINAL_MOUSE_AUTOHIDE:
774 self->mouse_autohide = g_value_get_boolean (value);
775 vte_terminal_set_mouse_autohide (VTE_TERMINAL(self->vte_term), self->mouse_autohide);
776 debug_printf ("terminal mouse autohide: %d\n", self->mouse_autohide);
780 /* We don't have this property... */
781 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
787 tilda_terminal_get_property (GObject *object,
792 TildaTerminal *self = (TildaTerminal *) object;
794 switch (property_id) {
796 case TILDA_TERMINAL_NUMBER:
797 g_value_set_int (value, self->number);
800 case TILDA_TERMINAL_PARENT_WINDOW:
801 g_value_set_pointer (value, self->parent_window);
804 case TILDA_TERMINAL_BACKGROUND_IMAGE:
805 g_value_set_string (value, self->background_image);
808 case TILDA_TERMINAL_SHELL:
809 g_value_set_string (value, self->shell);
812 case TILDA_TERMINAL_FONT:
813 g_value_set_string (value, self->font);
816 case TILDA_TERMINAL_TITLE:
817 g_value_set_string (value, self->title);
820 case TILDA_TERMINAL_WORKING_DIRECTORY:
821 g_value_set_string (value, self->working_directory);
824 case TILDA_TERMINAL_WEB_BROWSER:
825 g_value_set_string (value, self->web_browser);
828 case TILDA_TERMINAL_SCROLLBACK_LINES:
829 g_value_set_int (value, self->scrollback_lines);
832 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
833 g_value_set_int (value, self->transparency_percent);
836 case TILDA_TERMINAL_BACKSPACE_BINDING:
837 g_value_set_int (value, self->backspace_binding);
840 case TILDA_TERMINAL_DELETE_BINDING:
841 g_value_set_int (value, self->delete_binding);
844 case TILDA_TERMINAL_DYNAMIC_TITLE:
845 g_value_set_int (value, self->dynamic_title);
848 case TILDA_TERMINAL_EXIT_ACTION:
849 g_value_set_int (value, self->exit_action);
852 case TILDA_TERMINAL_SCROLLBAR_POSITION:
853 g_value_set_int (value, self->scrollbar_position);
856 case TILDA_TERMINAL_SCROLL_BACKGROUND:
857 g_value_set_boolean (value, self->scroll_background);
860 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
861 g_value_set_boolean (value, self->scroll_on_output);
864 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
865 g_value_set_boolean (value, self->scroll_on_keystroke);
868 case TILDA_TERMINAL_ANTIALIASED:
869 g_value_set_boolean (value, self->antialiased);
872 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
873 g_value_set_boolean (value, self->allow_bold_text);
876 case TILDA_TERMINAL_CURSOR_BLINKS:
877 g_value_set_boolean (value, self->cursor_blinks);
880 case TILDA_TERMINAL_AUDIBLE_BELL:
881 g_value_set_boolean (value, self->audible_bell);
884 case TILDA_TERMINAL_VISIBLE_BELL:
885 g_value_set_boolean (value, self->visible_bell);
888 case TILDA_TERMINAL_DOUBLE_BUFFERED:
889 g_value_set_boolean (value, self->double_buffered);
892 case TILDA_TERMINAL_MOUSE_AUTOHIDE:
893 g_value_set_boolean (value, self->mouse_autohide);
896 /* We don't have this property... */
897 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
903 tilda_terminal_constructor (GType type,
904 guint n_construct_properties,
905 GObjectConstructParam *construct_properties)
913 /* Invoke parent constructor */
914 TildaTerminalClass *klass;
915 klass = TILDA_TERMINAL_CLASS (g_type_class_peek (TILDA_TYPE_TERMINAL));
916 obj = parent_class->constructor (type,
917 n_construct_properties,
918 construct_properties);
920 /* Do other stuff here. The object is ready to go now, and all
921 * ctor properties have been set. */
922 self = TILDA_TERMINAL(obj);
924 /* Pack into the hbox */
925 gtk_box_pack_end (GTK_BOX(self->hbox), self->scrollbar, FALSE, FALSE, 0);
926 gtk_box_pack_end (GTK_BOX(self->hbox), self->vte_term, TRUE, TRUE, 0);
927 gtk_widget_show (self->scrollbar);
928 gtk_widget_show (self->vte_term);
929 gtk_widget_show (self->hbox);
931 /* Match URL's, etc */
932 ret = vte_terminal_match_add (VTE_TERMINAL(self->vte_term), DINGUS1);
933 vte_terminal_match_set_cursor_type (VTE_TERMINAL(self->vte_term), ret, GDK_HAND2);
934 ret = vte_terminal_match_add(VTE_TERMINAL(self->vte_term), DINGUS2);
935 vte_terminal_match_set_cursor_type (VTE_TERMINAL(self->vte_term), ret, GDK_HAND2);
937 /* Connect Signals */
938 g_signal_connect (G_OBJECT(self->vte_term), "child-exited",
939 G_CALLBACK(tilda_terminal_child_exited_cb), self);
940 g_signal_connect (G_OBJECT(self->vte_term), "eof",
941 G_CALLBACK(tilda_terminal_child_exited_cb), self);
942 g_signal_connect (G_OBJECT(self->vte_term), "window-title-changed",
943 G_CALLBACK(tilda_terminal_window_title_changed_cb), self);
944 g_signal_connect (G_OBJECT(self->vte_term), "button-press-event",
945 G_CALLBACK(tilda_terminal_button_press_cb), self);
947 /* Setup all of the defaults from the config file */
948 tilda_terminal_config_string_property (self, "background-image");
949 tilda_terminal_config_string_property (self, "shell");
950 tilda_terminal_config_string_property (self, "font");
951 tilda_terminal_config_string_property (self, "title");
952 tilda_terminal_config_string_property (self, "working-directory");
953 tilda_terminal_config_string_property (self, "web-browser");
955 tilda_terminal_config_int_property (self, "scrollback-lines");
956 tilda_terminal_config_int_property (self, "transparency-percent");
958 tilda_terminal_config_enum_property (self, "backspace-binding");
959 tilda_terminal_config_enum_property (self, "delete-binding");
960 tilda_terminal_config_enum_property (self, "dynamic-title");
961 tilda_terminal_config_enum_property (self, "exit-action");
962 tilda_terminal_config_enum_property (self, "scrollbar-position");
964 tilda_terminal_config_boolean_property (self, "scroll-background");
965 tilda_terminal_config_boolean_property (self, "scroll-on-output");
966 tilda_terminal_config_boolean_property (self, "scroll-on-keystroke");
967 tilda_terminal_config_boolean_property (self, "antialiased");
968 tilda_terminal_config_boolean_property (self, "allow-bold-text");
969 tilda_terminal_config_boolean_property (self, "cursor-blinks");
970 tilda_terminal_config_boolean_property (self, "audible-bell");
971 tilda_terminal_config_boolean_property (self, "visible-bell");
972 tilda_terminal_config_boolean_property (self, "double-buffered");
973 tilda_terminal_config_boolean_property (self, "mouse-autohide");
975 /* All right! We're all ready to go, so register with DBus, and lets start! */
976 tilda_terminal_dbus_register_object (self);
982 tilda_terminal_dispose (GObject *obj)
986 TildaTerminal *self = (TildaTerminal *) obj;
988 /* We don't want to run dispose twice, so just return immediately */
989 if (self->dispose_has_run)
992 self->dispose_has_run = TRUE;
995 * In dispose, you are supposed to free all types referenced from this
996 * object which might themselves hold a reference to self. Generally,
997 * the most simple solution is to unref all members on which you own a
1001 /* Chain up to the parent class */
1002 G_OBJECT_CLASS (parent_class)->dispose (obj);
1006 tilda_terminal_finalize (GObject *obj)
1010 TildaTerminal *self = (TildaTerminal *) obj;
1013 * Here, complete object destruction.
1014 * You might not need to do much...
1016 g_free (self->background_image);
1017 g_free (self->shell);
1018 g_free (self->font);
1019 g_free (self->title);
1020 g_free (self->working_directory);
1023 /* Chain up to the parent class */
1024 G_OBJECT_CLASS (parent_class)->finalize (obj);
1028 tilda_terminal_class_init (gpointer g_class,
1029 gpointer g_class_data)
1033 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
1034 TildaTerminalClass *klass = TILDA_TERMINAL_CLASS (g_class);
1037 /* Hook our functions to this type */
1038 gobject_class->set_property = tilda_terminal_set_property;
1039 gobject_class->get_property = tilda_terminal_get_property;
1040 gobject_class->dispose = tilda_terminal_dispose;
1041 gobject_class->finalize = tilda_terminal_finalize;
1042 gobject_class->constructor = tilda_terminal_constructor;
1044 parent_class = g_type_class_peek_parent (klass);
1046 /* Hook the TildaTerminal type into DBus */
1047 dbus_g_object_type_install_info (tilda_terminal_get_type(), &dbus_glib_tilda_terminal_object_info);
1049 /* Install all of the properties */
1050 pspec = g_param_spec_int ("number",
1051 _("Terminal number"),
1054 INT_MAX, // max value
1056 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
1058 g_object_class_install_property (gobject_class,
1059 TILDA_TERMINAL_NUMBER,
1062 pspec = g_param_spec_pointer ("parent-window",
1063 _("Pointer to terminal's parent TildaWindow"),
1065 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
1067 g_object_class_install_property (gobject_class,
1068 TILDA_TERMINAL_PARENT_WINDOW,
1071 pspec = g_param_spec_string ("background-image",
1072 _("Terminal's background image"),
1077 g_object_class_install_property (gobject_class,
1078 TILDA_TERMINAL_BACKGROUND_IMAGE,
1081 pspec = g_param_spec_string ("shell",
1082 _("Terminal's shell"),
1087 g_object_class_install_property (gobject_class,
1088 TILDA_TERMINAL_SHELL,
1091 pspec = g_param_spec_string ("font",
1092 _("Terminal's font"),
1097 g_object_class_install_property (gobject_class,
1098 TILDA_TERMINAL_FONT,
1101 pspec = g_param_spec_string ("title",
1102 _("Terminal's title"),
1107 g_object_class_install_property (gobject_class,
1108 TILDA_TERMINAL_TITLE,
1111 pspec = g_param_spec_string ("working-directory",
1112 _("Terminal's initial working directory"),
1117 g_object_class_install_property (gobject_class,
1118 TILDA_TERMINAL_WORKING_DIRECTORY,
1121 pspec = g_param_spec_string ("web-browser",
1122 _("Terminal's web browser command"),
1127 g_object_class_install_property (gobject_class,
1128 TILDA_TERMINAL_WEB_BROWSER,
1131 pspec = g_param_spec_int ("scrollback-lines",
1132 _("Terminal's scrollback amount (lines)"),
1135 INT_MAX, // TODO: artificially limit this?
1139 g_object_class_install_property (gobject_class,
1140 TILDA_TERMINAL_SCROLLBACK_LINES,
1143 pspec = g_param_spec_int ("transparency-percent",
1144 _("Terminal's transparency (percent)"),
1151 g_object_class_install_property (gobject_class,
1152 TILDA_TERMINAL_TRANSPARENCY_PERCENT,
1155 pspec = g_param_spec_int ("backspace-binding",
1156 _("Terminal's backspace binding"),
1159 VTE_ERASE_DELETE_SEQUENCE,
1163 g_object_class_install_property (gobject_class,
1164 TILDA_TERMINAL_BACKSPACE_BINDING,
1167 pspec = g_param_spec_int ("delete-binding",
1168 _("Terminal's delete binding"),
1171 VTE_ERASE_DELETE_SEQUENCE,
1175 g_object_class_install_property (gobject_class,
1176 TILDA_TERMINAL_DELETE_BINDING,
1179 pspec = g_param_spec_int ("dynamic-title",
1180 _("Terminal's dynamic title generation method"),
1187 g_object_class_install_property (gobject_class,
1188 TILDA_TERMINAL_DYNAMIC_TITLE,
1191 pspec = g_param_spec_int ("exit-action",
1192 _("Terminal's action upon child exit"),
1199 g_object_class_install_property (gobject_class,
1200 TILDA_TERMINAL_EXIT_ACTION,
1203 pspec = g_param_spec_int ("scrollbar-position",
1204 _("Terminal's scrollbar position"),
1211 g_object_class_install_property (gobject_class,
1212 TILDA_TERMINAL_SCROLLBAR_POSITION,
1215 pspec = g_param_spec_boolean ("scroll-background",
1216 _("Controls terminal's scrolling behavior"),
1221 g_object_class_install_property (gobject_class,
1222 TILDA_TERMINAL_SCROLL_BACKGROUND,
1225 pspec = g_param_spec_boolean ("scroll-on-output",
1226 _("Controls terminal's scrolling behavior on output"),
1231 g_object_class_install_property (gobject_class,
1232 TILDA_TERMINAL_SCROLL_ON_OUTPUT,
1235 pspec = g_param_spec_boolean ("scroll-on-keystroke",
1236 _("Controls the terminal's scrolling behavior on keystroke"),
1237 NULL, FALSE, G_PARAM_READWRITE);
1239 g_object_class_install_property (gobject_class,
1240 TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
1243 pspec = g_param_spec_boolean ("antialiased",
1244 _("Attempt to antialias fonts"),
1245 NULL, FALSE, G_PARAM_READWRITE);
1247 g_object_class_install_property (gobject_class,
1248 TILDA_TERMINAL_ANTIALIASED,
1251 pspec = g_param_spec_boolean ("allow-bold-text",
1252 _("Allow bold text"),
1253 NULL, FALSE, G_PARAM_READWRITE);
1255 g_object_class_install_property (gobject_class,
1256 TILDA_TERMINAL_ALLOW_BOLD_TEXT,
1259 pspec = g_param_spec_boolean ("cursor-blinks",
1260 _("Enable cursor blinking"),
1261 NULL, FALSE, G_PARAM_READWRITE);
1263 g_object_class_install_property (gobject_class,
1264 TILDA_TERMINAL_CURSOR_BLINKS,
1267 pspec = g_param_spec_boolean ("audible-bell",
1268 _("Enable the audible bell"),
1269 NULL, FALSE, G_PARAM_READWRITE);
1271 g_object_class_install_property (gobject_class,
1272 TILDA_TERMINAL_AUDIBLE_BELL,
1275 pspec = g_param_spec_boolean ("visible-bell",
1276 _("Enable the visible bell"),
1277 NULL, FALSE, G_PARAM_READWRITE);
1279 g_object_class_install_property (gobject_class,
1280 TILDA_TERMINAL_VISIBLE_BELL,
1283 pspec = g_param_spec_boolean ("double-buffered",
1284 _("Double buffer the terminal"),
1285 NULL, FALSE, G_PARAM_READWRITE);
1287 g_object_class_install_property (gobject_class,
1288 TILDA_TERMINAL_DOUBLE_BUFFERED,
1291 pspec = g_param_spec_boolean ("mouse-autohide",
1292 _("Hide the mouse cursor while typing"),
1293 NULL, FALSE, G_PARAM_READWRITE);
1295 g_object_class_install_property (gobject_class,
1296 TILDA_TERMINAL_MOUSE_AUTOHIDE,
1301 tilda_terminal_get_type (void)
1303 static GType type = 0;
1307 static const GTypeInfo info = {
1308 sizeof (TildaTerminalClass),
1309 NULL, /* base_init */
1310 NULL, /* base_finalize */
1311 tilda_terminal_class_init, /* class_init */
1312 NULL, /* class_finalize */
1313 NULL, /* class_data */
1314 sizeof (TildaTerminal),
1315 0, /* n_preallocs */
1316 tilda_terminal_instance_init, /* instance_init */
1319 type = g_type_register_static (G_TYPE_OBJECT,
1320 "TildaTerminalType",
1328 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */