Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions data/io.elementary.code.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
<summary>Preferred Font</summary>
<description>Set the preferred font.</description>
</key>
<key name="terminal-fontscale" type="d">
<range min="0.5" max="2.0"/>
<default>1.0</default>
<summary>Terminal pane font scale</summary>
<description>The system terminal font is scaled by this factor in the terminal pane </description>
</key>
<key name="style-scheme" type="s">
<default>'elementary-light'</default>
<summary>Preferred Style Scheme</summary>
Expand Down
21 changes: 15 additions & 6 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -871,20 +871,29 @@ public class Scratch.MainWindow : Hdy.Window {
}

public void set_default_zoom () {
terminal.set_default_font_size ();
Scratch.settings.set_string ("font", get_current_font () + " " + get_default_font_size ().to_string ());
if (terminal.terminal.has_focus) {
terminal.set_default_font_size ();
} else {
Scratch.settings.set_string ("font", get_current_font () + " " + get_default_font_size ().to_string ());
}
}

// Ctrl + scroll
public void action_zoom_in () {
terminal.increment_size ();
zooming (Gdk.ScrollDirection.UP);
if (terminal.terminal.has_focus) {
terminal.increment_size ();
} else {
zooming (Gdk.ScrollDirection.UP);
}
}

// Ctrl + scroll
public void action_zoom_out () {
terminal.decrement_size ();
zooming (Gdk.ScrollDirection.DOWN);
if (terminal.terminal.has_focus) {
terminal.decrement_size ();
} else {
zooming (Gdk.ScrollDirection.DOWN);
}
}

private void zooming (Gdk.ScrollDirection direction) {
Expand Down
37 changes: 31 additions & 6 deletions src/Widgets/Terminal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public class Code.Terminal : Gtk.Box {
public const string ACTION_COPY = "action-copy";
public const string ACTION_PASTE = "action-paste";

private const double MAX_SCALE = 5.0;
private const double MIN_SCALE = 0.2;
private const double SCROLL_THRESHOLD = 1.0;
private const double MAX_SCALE = 2.0;
private const double MIN_SCALE = 0.5;
private const string LEGACY_SETTINGS_SCHEMA = "org.pantheon.terminal.settings";
private const string SETTINGS_SCHEMA = "io.elementary.terminal.settings";
private const string GNOME_DESKTOP_INTERFACE_SCHEMA = "org.gnome.desktop.interface";
Expand All @@ -25,6 +26,7 @@ public class Code.Terminal : Gtk.Box {

public Vte.Terminal terminal { get; construct; }
private Gtk.EventControllerKey key_controller;
private Gtk.EventControllerScroll scroll_controller;
private Gtk.GestureMultiPress button_controller;
private Settings? terminal_settings = null;
private Settings? gnome_interface_settings = null;
Expand All @@ -34,6 +36,7 @@ public class Code.Terminal : Gtk.Box {

private GLib.Pid child_pid;
private Gtk.Clipboard current_clipboard;
private double total_delta_y = 0;
private Menu menu_model;

private Scratch.Application application;
Expand All @@ -43,10 +46,14 @@ public class Code.Terminal : Gtk.Box {
terminal = new Vte.Terminal () {
hexpand = true,
vexpand = true,
scroll_unit_is_pixels = true,
scrollback_lines = -1,
cursor_blink_mode = SYSTEM // There is no Terminal setting so follow Gnome
};

var scrolled_window = new Gtk.ScrolledWindow (null, terminal.get_vadjustment ());
scrolled_window.add (terminal);

// Set font, allow-bold, audible-bell, background, foreground, and palette of pantheon-terminal
var schema_source = SettingsSchemaSource.get_default ();
var terminal_schema = schema_source.lookup (SETTINGS_SCHEMA, true);
Expand Down Expand Up @@ -97,6 +104,7 @@ public class Code.Terminal : Gtk.Box {
// "org.gnome.desktop.interface.color-scheme"
}

Scratch.settings.bind ("terminal-fontscale", terminal, "font-scale", DEFAULT);
// Always monitor changes in systen font as that is what Terminal usually follows
// The terminal font key is by default "" and can only be changed by editing the settings externally
application.notify["system-monospace-font"].connect (() => {
Expand Down Expand Up @@ -146,6 +154,27 @@ public class Code.Terminal : Gtk.Box {
};
key_controller.key_pressed.connect (key_pressed);

scroll_controller = new Gtk.EventControllerScroll (this, VERTICAL) {
propagation_phase = CAPTURE
};
scroll_controller.scroll.connect ((dx, dy) => {
Gdk.ModifierType state;
Gtk.get_current_event_state (out state);
var mods = state & Gdk.ModifierType.MODIFIER_MASK;
if ((mods & Gdk.ModifierType.CONTROL_MASK) > 0) {
total_delta_y += dy;
if (total_delta_y > SCROLL_THRESHOLD) {
total_delta_y = 0;
decrement_size ();
} else if (total_delta_y < -SCROLL_THRESHOLD) {
total_delta_y = 0;
increment_size ();
}
} else {
Gtk.propagate_event (scrolled_window, Gtk.get_current_event ());
}
});

// Cannot use event controller in Gtk3 because of https://gitlab.gnome.org/GNOME/gtk/-/issues/7225
terminal.enter_notify_event.connect (() => {
if (!terminal.has_focus) {
Expand Down Expand Up @@ -177,10 +206,6 @@ public class Code.Terminal : Gtk.Box {

spawn_shell (Scratch.saved_state.get_string ("last-opened-path"));

var scrolled_window = new Gtk.ScrolledWindow (null, terminal.get_vadjustment ()) {
child = terminal
};

add (scrolled_window);
show_all ();
}
Expand Down