Commit 13273962 authored by Christian Persch's avatar Christian Persch

vteapp: Reindent

Fix vala mode indentation. And fix setup so that vala code is never
using tabs!
parent 52662317
......@@ -2,4 +2,9 @@
(indent-tabs-mode . nil)
(c-basic-offset . 8)
(tab-width . 8)
(show-trailing-whitespace . t))))
(show-trailing-whitespace . t)))
(vala-mode . ((c-file-style . "GNU")
(indent-tabs-mode . nil)
(c-basic-offset . 2)
(tab-width . 2)
(show-trailing-whitespace . t))))
......@@ -21,782 +21,782 @@ namespace Test
class Window : Gtk.ApplicationWindow
{
private Vte.Terminal terminal;
private Gtk.Scrollbar scrollbar;
private Gtk.Clipboard clipboard;
private GLib.Pid child_pid;
private string[] builtin_dingus = {
"(((gopher|news|telnet|nntp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?",
"(((gopher|news|telnet|nntp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"]"
};
private const GLib.ActionEntry[] action_entries = {
{ "copy", action_copy_cb },
{ "copy-match", action_copy_match_cb, "s" },
{ "paste", action_paste_cb },
{ "reset", action_reset_cb }
};
private Vte.Terminal terminal;
private Gtk.Scrollbar scrollbar;
private Gtk.Clipboard clipboard;
private GLib.Pid child_pid;
private string[] builtin_dingus = {
"(((gopher|news|telnet|nntp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?",
"(((gopher|news|telnet|nntp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"]"
};
public Window(App app)
{
Object(application: app);
private const GLib.ActionEntry[] action_entries = {
{ "copy", action_copy_cb },
{ "copy-match", action_copy_match_cb, "s" },
{ "paste", action_paste_cb },
{ "reset", action_reset_cb }
};
add_action_entries (action_entries, this);
public Window(App app)
{
Object(application: app);
/* set_resize_mode(Gtk.ResizeMode.IMMEDIATE); */
add_action_entries (action_entries, this);
clipboard = get_clipboard(Gdk.SELECTION_CLIPBOARD);
clipboard.owner_change.connect(clipboard_owner_change_cb);
/* set_resize_mode(Gtk.ResizeMode.IMMEDIATE); */
title = "Terminal";
clipboard = get_clipboard(Gdk.SELECTION_CLIPBOARD);
clipboard.owner_change.connect(clipboard_owner_change_cb);
/* Set ARGB visual */
if (!App.Options.no_argb_visual) {
var screen = get_screen();
Gdk.Visual? visual = screen.get_rgba_visual();
if (visual != null)
set_visual(visual);
}
title = "Terminal";
var ui = new Gtk.Builder.from_resource("/org/gnome/vte/test/app/ui/window.ui");
add(ui.get_object("main-box") as Gtk.Widget);
/* Set ARGB visual */
if (!App.Options.no_argb_visual) {
var screen = get_screen();
Gdk.Visual? visual = screen.get_rgba_visual();
if (visual != null)
set_visual(visual);
}
var box = ui.get_object("terminal-box") as Gtk.Box;
var ui = new Gtk.Builder.from_resource("/org/gnome/vte/test/app/ui/window.ui");
add(ui.get_object("main-box") as Gtk.Widget);
if (App.Options.no_toolbar) {
var toolbar = ui.get_object("toolbar") as Gtk.Widget;
toolbar.hide();
}
var box = ui.get_object("terminal-box") as Gtk.Box;
if (App.Options.no_toolbar) {
var toolbar = ui.get_object("toolbar") as Gtk.Widget;
toolbar.hide();
}
terminal = new Vte.Terminal();
/* Connect scrollbar */
scrollbar = ui.get_object("scrollbar") as Gtk.Scrollbar;
scrollbar.set_adjustment(terminal.get_vadjustment());
/* Signals */
terminal.button_press_event.connect(button_press_event_cb);
terminal.char_size_changed.connect(char_size_changed_cb);
terminal.child_exited.connect(child_exited_cb);
terminal.decrease_font_size.connect(decrease_font_size_cb);
terminal.deiconify_window.connect(deiconify_window_cb);
terminal.icon_title_changed.connect(icon_title_changed_cb);
terminal.iconify_window.connect(iconify_window_cb);
terminal.increase_font_size.connect(increase_font_size_cb);
terminal.lower_window.connect(lower_window_cb);
terminal.maximize_window.connect(maximize_window_cb);
terminal.move_window.connect(move_window_cb);
terminal.raise_window.connect(raise_window_cb);
terminal.realize.connect(realize_cb);
terminal.refresh_window.connect(refresh_window_cb);
terminal.resize_window.connect(resize_window_cb);
terminal.restore_window.connect(restore_window_cb);
terminal.selection_changed.connect(selection_changed_cb);
terminal.status_line_changed.connect(status_line_changed_cb);
terminal.window_title_changed.connect(window_title_changed_cb);
if (App.Options.object_notifications)
terminal.notify.connect(notify_cb);
/* Settings */
if (App.Options.no_double_buffer)
terminal.set_double_buffered(true);
if (App.Options.termcap != null)
terminal.set_emulation(App.Options.termcap);
if (App.Options.encoding != null)
terminal.set_encoding(App.Options.encoding);
terminal.set_audible_bell(App.Options.audible);
terminal.set_cjk_ambiguous_width(App.Options.get_cjk_ambiguous_width());
terminal.set_cursor_blink_mode(App.Options.get_cursor_blink_mode());
terminal.set_cursor_shape(App.Options.get_cursor_shape());
terminal.set_mouse_autohide(true);
terminal.set_rewrap_on_resize(!App.Options.no_rewrap);
terminal.set_scroll_on_output(false);
terminal.set_scroll_on_keystroke(true);
terminal.set_scrollback_lines(App.Options.scrollback_lines);
terminal.set_visible_bell(!App.Options.audible);
/* Style */
if (App.Options.font_string != null) {
var desc = Pango.FontDescription.from_string(App.Options.font_string);
terminal.set_font(desc);
}
terminal.set_colors(App.Options.get_color_fg(),
App.Options.get_color_bg(),
null);
terminal.set_color_cursor(App.Options.get_color_cursor());
terminal.set_color_highlight(App.Options.get_color_hl_bg());
terminal.set_color_highlight_foreground(App.Options.get_color_hl_fg());
/* Dingus */
if (!App.Options.no_builtin_dingus)
add_dingus(builtin_dingus);
if (App.Options.dingus != null)
add_dingus(App.Options.dingus);
/* Property actions */
add_action(new GLib.PropertyAction ("input-enabled", terminal, "input-enabled"));
/* Done! */
box.pack_start(terminal);
terminal.show();
update_paste_sensitivity();
update_copy_sensitivity();
terminal.grab_focus();
assert(!get_realized());
}
private void add_dingus(string[] dingus)
{
const Gdk.CursorType cursors[] = { Gdk.CursorType.GUMBY, Gdk.CursorType.HAND1 };
for (int i = 0; i < dingus.length; ++i) {
try {
GLib.Regex regex;
int tag;
regex = new GLib.Regex(dingus[i], GLib.RegexCompileFlags.OPTIMIZE, 0);
tag = terminal.match_add_gregex(regex, 0);
terminal.match_set_cursor_type(tag, cursors[i % cursors.length]);
} catch (Error e) {
printerr("Failed to compile regex \"%s\": %s\n", dingus[i], e.message);
}
}
}
private void adjust_font_size(double factor)
{
var columns = terminal.get_column_count();
var rows = terminal.get_row_count();
terminal.set_font_scale(terminal.get_font_scale() * factor);
update_geometry();
resize_to_geometry((int)columns, (int)rows);
}
public void apply_geometry()
{
/* The terminal needs to be realized first, so that when parsing the
* geometry, the right geometry hints are already in place.
*/
terminal.realize();
if (App.Options.geometry != null) {
if (parse_geometry(App.Options.geometry)) {
/* After parse_geometry(), we can get the default size in
* width/height increments, i.e. in grid size.
*/
int columns, rows;
get_default_size(out columns, out rows);
terminal.set_size(columns, rows);
resize_to_geometry(columns, rows);
} else
printerr("Failed to parse geometry spec \"%s\"\n", App.Options.geometry);
} else {
/* In GTK+ 3.0, the default size of a window comes from its minimum
* size not its natural size, so we need to set the right default size
* explicitly */
set_default_geometry((int)terminal.get_column_count(),
(int)terminal.get_row_count());
}
}
private void launch_command(string command) throws Error
{
string[] argv;
Shell.parse_argv(command, out argv);
terminal.spawn_sync(App.Options.get_pty_flags(),
App.Options.working_directory,
argv,
App.Options.environment,
GLib.SpawnFlags.SEARCH_PATH,
null, /* child setup */
out child_pid,
null /* cancellable */);
print("Fork succeeded, PID %d\n", child_pid);
}
private void launch_shell() throws Error
{
string? shell;
shell = Vte.get_user_shell();
if (shell == null || shell[0] == '\0')
shell = Environment.get_variable("SHELL");
if (shell == null || shell[0] == '\0')
shell = "/bin/sh";
launch_command(shell);
}
private void fork() throws Error
{
Vte.Pty pty;
Posix.pid_t pid;
pty = new Vte.Pty.sync(App.Options.get_pty_flags(), null);
pid = Posix.fork();
switch (pid) {
case -1: /* error */
printerr("Error forking: %m");
break;
case 0: /* child */ {
pty.child_setup();
for (int i = 0; ; i++) {
switch (i % 3) {
case 0:
case 1:
print("%d\n", i);
break;
case 2:
printerr("%d\n", i);
break;
}
Posix.sleep(1);
}
}
default: /* parent */
terminal.set_pty(pty);
terminal.watch_child(pid);
print("Child PID is %d (mine is %d).\n", (int)pid, (int)Posix.getpid());
break;
}
}
public void launch()
{
try {
if (App.Options.command != null)
launch_command(App.Options.command);
else if (!App.Options.no_shell)
launch_shell();
else
fork();
} catch (Error e) {
printerr("Error: %s\n", e.message);
}
}
private void update_copy_sensitivity()
{
var action = lookup_action("copy") as GLib.SimpleAction;
action.set_enabled(terminal.get_has_selection());
}
private void update_paste_sensitivity()
{
Gdk.Atom[] targets;
bool can_paste;
if (clipboard.wait_for_targets(out targets))
can_paste = Gtk.targets_include_text(targets);
else
can_paste = false;
var action = lookup_action("paste") as GLib.SimpleAction;
action.set_enabled(can_paste);
}
private void update_geometry()
{
if (App.Options.no_geometry_hints)
return;
if (!terminal.get_realized())
return;
terminal.set_geometry_hints_for_window(this);
}
/* Callbacks */
private void action_copy_cb()
{
terminal.copy_clipboard();
}
private void action_copy_match_cb(GLib.SimpleAction action, GLib.Variant? parameter)
{
size_t len;
unowned string str = parameter.get_string(out len);
clipboard.set_text(str, (int)len);
}
private void action_paste_cb()
{
terminal.paste_clipboard();
}
private void action_reset_cb()
{
bool clear;
Gdk.ModifierType modifiers;
if (Gtk.get_current_event_state(out modifiers))
clear = (modifiers & Gdk.ModifierType.CONTROL_MASK) != 0;
else
clear = false;
terminal.reset(true, clear);
}
private bool button_press_event_cb(Gtk.Widget widget, Gdk.EventButton event)
{
if (event.button != 3)
return false;
if (App.Options.no_context_menu)
return false;
var match = terminal.match_check_event(event, null);
var menu = new GLib.Menu();
menu.append("_Copy", "win.copy");
if (match != null)
menu.append("Copy _Match", "win.copy-match::" + match);
menu.append("_Paste", "win.paste");
var popup = new Gtk.Menu.from_model(menu);
popup.attach_to_widget(this, null);
popup.popup(null, null, null, event.button, event.time);
return false;
}
private void char_size_changed_cb(Vte.Terminal terminal, uint width, uint height)
{
update_geometry();
}
private void child_exited_cb(Vte.Terminal terminal, int status)
{
printerr("Child exited with status %x\n", status);
if (App.Options.output_filename != null) {
try {
var file = GLib.File.new_for_commandline_arg(App.Options.output_filename);
var stream = file.replace(null, false, GLib.FileCreateFlags.NONE, null);
terminal.write_contents(stream, Vte.WriteFlags.DEFAULT, null);
} catch (Error e) {
printerr("Failed to write output to \"%s\": %s\n",
App.Options.output_filename, e.message);
}
}
if (App.Options.keep)
return;
destroy();
}
private void clipboard_owner_change_cb(Gtk.Clipboard clipboard, Gdk.Event event)
{
update_paste_sensitivity();
}
private void decrease_font_size_cb(Vte.Terminal terminal)
{
adjust_font_size(1.0 / 1.2);
}
public void deiconify_window_cb(Vte.Terminal terminal)
{
deiconify();
}
private void icon_title_changed_cb(Vte.Terminal terminal)
{
get_window().set_icon_name(terminal.get_icon_title());
}
private void iconify_window_cb(Vte.Terminal terminal)
{
iconify();
}
private void increase_font_size_cb(Vte.Terminal terminal)
{
adjust_font_size(1.2);
}
private void lower_window_cb(Vte.Terminal terminal)
{
if (!get_realized())
return;
get_window().lower();
}
private void maximize_window_cb(Vte.Terminal terminal)
{
maximize();
}
private void move_window_cb(Vte.Terminal terminal, uint x, uint y)
{
move((int)x, (int)y);
}
private void notify_cb(Object object, ParamSpec pspec)
{
if (pspec.owner_type != typeof(Vte.Terminal))
return;
var value = GLib.Value(pspec.value_type);
object.get_property(pspec.name, ref value);
var str = value.strdup_contents();
print("NOTIFY property \"%s\" value %s\n", pspec.name, str);
}
private void raise_window_cb(Vte.Terminal terminal)
{
if (!get_realized())
return;
get_window().raise();
}
private void realize_cb(Gtk.Widget widget)
{
update_geometry();
}
private void refresh_window_cb(Vte.Terminal terminal)
{
queue_draw();
}
private void resize_window_cb(Vte.Terminal terminal, uint columns, uint rows)
{
if (columns < 2 || rows < 2)
return;
terminal.set_size((int)columns, (int)rows);
resize_to_geometry((int)columns, (int)rows);
}
private void restore_window_cb(Vte.Terminal terminal)
{
unmaximize();
}
private void selection_changed_cb(Vte.Terminal terminal)
{
update_copy_sensitivity();
}
private void status_line_changed_cb(Vte.Terminal terminal)
{
print("Status: `%s'\n", terminal.get_status_line());
}
private void window_title_changed_cb(Vte.Terminal terminal)
{
set_title(terminal.get_window_title());
}
terminal = new Vte.Terminal();
/* Connect scrollbar */
scrollbar = ui.get_object("scrollbar") as Gtk.Scrollbar;
scrollbar.set_adjustment(terminal.get_vadjustment());
/* Signals */
terminal.button_press_event.connect(button_press_event_cb);
terminal.char_size_changed.connect(char_size_changed_cb);
terminal.child_exited.connect(child_exited_cb);
terminal.decrease_font_size.connect(decrease_font_size_cb);
terminal.deiconify_window.connect(deiconify_window_cb);
terminal.icon_title_changed.connect(icon_title_changed_cb);
terminal.iconify_window.connect(iconify_window_cb);
terminal.increase_font_size.connect(increase_font_size_cb);
terminal.lower_window.connect(lower_window_cb);
terminal.maximize_window.connect(maximize_window_cb);
terminal.move_window.connect(move_window_cb);
terminal.raise_window.connect(raise_window_cb);
terminal.realize.connect(realize_cb);
terminal.refresh_window.connect(refresh_window_cb);
terminal.resize_window.connect(resize_window_cb);
terminal.restore_window.connect(restore_window_cb);
terminal.selection_changed.connect(selection_changed_cb);
terminal.status_line_changed.connect(status_line_changed_cb);
terminal.window_title_changed.connect(window_title_changed_cb);
if (App.Options.object_notifications)
terminal.notify.connect(notify_cb);
/* Settings */
if (App.Options.no_double_buffer)
terminal.set_double_buffered(true);
if (App.Options.termcap != null)
terminal.set_emulation(App.Options.termcap);
if (App.Options.encoding != null)
terminal.set_encoding(App.Options.encoding);
terminal.set_audible_bell(App.Options.audible);
terminal.set_cjk_ambiguous_width(App.Options.get_cjk_ambiguous_width());
terminal.set_cursor_blink_mode(App.Options.get_cursor_blink_mode());
terminal.set_cursor_shape(App.Options.get_cursor_shape());
terminal.set_mouse_autohide(true);
terminal.set_rewrap_on_resize(!App.Options.no_rewrap);
terminal.set_scroll_on_output(false);
terminal.set_scroll_on_keystroke(true);
terminal.set_scrollback_lines(App.Options.scrollback_lines);
terminal.set_visible_bell(!App.Options.audible);
/* Style */
if (App.Options.font_string != null) {
var desc = Pango.FontDescription.from_string(App.Options.font_string);
terminal.set_font(desc);
}
terminal.set_colors(App.Options.get_color_fg(),
App.Options.get_color_bg(),
null);
terminal.set_color_cursor(App.Options.get_color_cursor());
terminal.set_color_highlight(App.Options.get_color_hl_bg());
terminal.set_color_highlight_foreground(App.Options.get_color_hl_fg());
/* Dingus */
if (!App.Options.no_builtin_dingus)
add_dingus(builtin_dingus);
if (App.Options.dingus != null)
add_dingus(App.Options.dingus);
/* Property actions */
add_action(new GLib.PropertyAction ("input-enabled", terminal, "input-enabled"));
/* Done! */
box.pack_start(terminal);
terminal.show();
update_paste_sensitivity();
update_copy_sensitivity();
terminal.grab_focus();
assert(!get_realized());
}
private void add_dingus(string[] dingus)
{
const Gdk.CursorType cursors[] = { Gdk.CursorType.GUMBY, Gdk.CursorType.HAND1 };
for (int i = 0; i < dingus.length; ++i) {
try {
GLib.Regex regex;
int tag;
regex = new GLib.Regex(dingus[i], GLib.RegexCompileFlags.OPTIMIZE, 0);
tag = terminal.match_add_gregex(regex, 0);
terminal.match_set_cursor_type(tag, cursors[i % cursors.length]);
} catch (Error e) {
printerr("Failed to compile regex \"%s\": %s\n", dingus[i], e.message);
}
}
}
private void adjust_font_size(double factor)
{
var columns = terminal.get_column_count();
var rows = terminal.get_row_count();
terminal.set_font_scale(terminal.get_font_scale() * factor);
update_geometry();
resize_to_geometry((int)columns, (int)rows);
}
public void apply_geometry()
{
/* The terminal needs to be realized first, so that when parsing the
* geometry, the right geometry hints are already in place.
*/
terminal.realize();
if (App.Options.geometry != null) {
if (parse_geometry(App.Options.geometry)) {
/* After parse_geometry(), we can get the default size in
* width/height increments, i.e. in grid size.
*/
int columns, rows;
get_default_size(out columns, out rows);
terminal.set_size(columns, rows);
resize_to_geometry(columns, rows);
} else
printerr("Failed to parse geometry spec \"%s\"\n", App.Options.geometry);
} else {
/* In GTK+ 3.0, the default size of a window comes from its minimum
* size not its natural size, so we need to set the right default size
* explicitly */
set_default_geometry((int)terminal.get_column_count(),
(int)terminal.get_row_count());
}
}
private void launch_command(string command) throws Error
{
string[] argv;
Shell.parse_argv(command, out argv);
terminal.spawn_sync(App.Options.get_pty_flags(),
App.Options.working_directory,
argv,
App.Options.environment,
GLib.SpawnFlags.SEARCH_PATH,
null, /* child setup */
out child_pid,
null /* cancellable */);
print("Fork succeeded, PID %d\n", child_pid);
}
private void launch_shell() throws Error
{
string? shell;
shell = Vte.get_user_shell();
if (shell == null || shell[0] == '\0')
shell = Environment.get_variable("SHELL");
if (shell == null || shell[0] == '\0')
shell = "/bin/sh";
launch_command(shell);
}
private void fork() throws Error
{
Vte.Pty pty;
Posix.pid_t pid;
pty = new Vte.Pty.sync(App.Options.get_pty_flags(), null);
pid = Posix.fork();
switch (pid) {
case -1: /* error */
printerr("Error forking: %m");
break;
case 0: /* child */ {
pty.child_setup();
for (int i = 0; ; i++) {
switch (i % 3) {
case 0:
case 1:
print("%d\n", i);
break;
case 2:
printerr("%d\n", i);
break;