Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk4: fix tests #811

Draft
wants to merge 17 commits into
base: jeremypw/gtk4
Choose a base branch
from
Draft
104 changes: 81 additions & 23 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

public class Terminal.Application : Gtk.Application {
public static string send_process_finished_bash;
public int minimum_width;
public int minimum_height;

Expand All @@ -14,18 +15,34 @@ public class Terminal.Application : Gtk.Application {
public static GLib.Settings settings;
public static GLib.Settings settings_sys;

public bool is_testing { get; set construct; }
public bool is_testing { get; construct; }

private static Themes themes;

public Application () {
public Application (bool _is_testing = false) {
Object (
is_testing: _is_testing,
application_id: "io.elementary.terminal", /* Ensures only one instance runs */
flags: ApplicationFlags.HANDLES_COMMAND_LINE | ApplicationFlags.CAN_OVERRIDE_APP_ID
);

stdout.printf (" Application new \n");
}

construct {
if (is_testing) {
stdout.printf (" App construct - is testing\n");
send_process_finished_bash = "";
} else {
stdout.printf (" App construct - NOT testing\n");
send_process_finished_bash = "dbus-send --type=method_call " +
"--session --dest=io.elementary.terminal " +
"/io/elementary/terminal " +
"io.elementary.terminal.ProcessFinished " +
"string:$PANTHEON_TERMINAL_ID " +
"string:\"$(fc -nl -1 | cut -c 3-)\" " +
"int32:\$__bp_last_ret_value >/dev/null 2>&1";
}
Intl.setlocale (LocaleCategory.ALL, "");
Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
Expand Down Expand Up @@ -66,9 +83,16 @@ public class Terminal.Application : Gtk.Application {
add_main_option (
"commandline", 'x', 0, OptionArg.FILENAME, _("Run remainder of line as a command in terminal"), "COMMAND"
);
stdout.printf (" End of application construct \n");
}

~Application () {
stdout.printf (" App destruct \n");

}

protected override bool local_command_line (ref unowned string[] args, out int exit_status) {
stdout.printf (" app local commandline \n");
bool show_help = false;

for (uint i = 1; args[i] != null; i++) {
Expand Down Expand Up @@ -123,10 +147,12 @@ public class Terminal.Application : Gtk.Application {
}

protected override int handle_local_options (VariantDict options) {
stdout.printf (" App handle local options \n");
unowned string working_directory;
unowned string[] args;

if (options.lookup ("working-directory", "^&ay", out working_directory)) {
stdout.printf (" options lookup working directory \n");
if (working_directory != "\0") {
Environment.set_current_dir (
Utils.sanitize_path (working_directory, Environment.get_current_dir (), false)
Expand All @@ -138,6 +164,7 @@ public class Terminal.Application : Gtk.Application {
}

if (options.lookup (OPTION_REMAINING, "^a&ay", out args)) {
stdout.printf (" options lookup OPTION_REMAINING \n");
if (commandline != "\0") {
commandline += " %s".printf (string.joinv (" ", args));
} else {
Expand All @@ -149,10 +176,14 @@ public class Terminal.Application : Gtk.Application {
options.insert ("commandline", "^&ay", commandline.escape ());
}

stdout.printf (" return -1 from handle_local_options \n");
return -1;
}

protected override bool dbus_register (DBusConnection connection, string object_path) throws Error {
// if (is_testing) {
// return true;
// }
base.dbus_register (connection, object_path);

var dbus = new DBus ();
Expand Down Expand Up @@ -187,7 +218,7 @@ public class Terminal.Application : Gtk.Application {
terminal.tab.icon = process_icon;
}

if (!get_active_window ().is_active) {
if (!is_testing && !get_active_window ().is_active) {
var notification = new Notification (process_string);
notification.set_body (process);
notification.set_icon (process_icon);
Expand All @@ -200,28 +231,35 @@ public class Terminal.Application : Gtk.Application {
}

protected override void startup () {
base.startup ();
Granite.init ();
Adw.init ();
stdout.printf (" App startup \n");

saved_state = new GLib.Settings ("io.elementary.terminal.saved-state");
base.startup ();
stdout.printf (" after base startup \n");
// saved_state = new GLib.Settings ("io.elementary.terminal.saved-state");
// stdout.printf (" after saved state init \n");
settings = new GLib.Settings ("io.elementary.terminal.settings");
stdout.printf (" after settings init \n");
settings_sys = new GLib.Settings ("org.gnome.desktop.interface");
stdout.printf (" after settings_sys init \n");
themes = new Themes ();
stdout.printf (" after themes init \n");
// if (!is_testing) {
var provider = new Gtk.CssProvider ();
provider.load_from_resource ("/io/elementary/terminal/Application.css");

var provider = new Gtk.CssProvider ();
provider.load_from_resource ("/io/elementary/terminal/Application.css");

/* Vte.Terminal itself registers its default styling with the APPLICATION priority:
* https://gitlab.gnome.org/GNOME/vte/blob/0.68.0/src/vtegtk.cc#L844-847
* To be able to overwrite their styles, we need to use +1.
*/
Gtk.StyleContext.add_provider_for_display (
Gdk.Display.get_default (),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + 1
);

/* Vte.Terminal itself registers its default styling with the APPLICATION priority:
* https://gitlab.gnome.org/GNOME/vte/blob/0.68.0/src/vtegtk.cc#L844-847
* To be able to overwrite their styles, we need to use +1.
*/
Gtk.StyleContext.add_provider_for_display (
Gdk.Display.get_default (),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + 1
);
// }
stdout.printf (" after providers init \n");
stdout.printf (" adding actions \n");
var new_window_action = new SimpleAction ("new-window", null);
new_window_action.activate.connect (() => {
new MainWindow (this, active_window == null).present ();
Expand All @@ -232,24 +270,38 @@ public class Terminal.Application : Gtk.Application {

add_action (new_window_action);
add_action (quit_action);

stdout.printf (" set accels \n");
set_accels_for_action ("app.new-window", { "<Control><Shift>N" });
set_accels_for_action ("app.quit", { "<Control><Shift>Q" });
stdout.printf (" after startup \n");



Granite.init ();
stdout.printf (" after Granite init \n");
// Adw.init ();
// stdout.printf (" after Adw init \n");



}

protected override int command_line (ApplicationCommandLine command_line) {
stdout.printf (" App commandline \n");
unowned var options = command_line.get_options_dict ();
var window = (MainWindow) active_window;
var is_first_window = window == null;
bool new_window;

// Always restore tabs if creating first window, but no extra tab at this stage
if (is_first_window || options.lookup ("new-window", "b", out new_window) && new_window) {
stdout.printf ("Creating new window \n");
window = new MainWindow (this, is_first_window);
}

// If a specified working directory is not requested, use the current working directory from the commandline
unowned var working_directory = command_line.get_cwd ();
unowned var working_directory = command_line.get_cwd () ?? "NULL";
stdout.printf ("Current working dir %s\n", working_directory);
unowned string[] commands;
unowned string command;
bool new_tab, minimized;
Expand All @@ -259,24 +311,28 @@ public class Terminal.Application : Gtk.Application {
// If "execute" option or "commandline" option used ignore any "new-tab option
// because these add new tab(s) already
if (options.lookup ("execute", "^a&ay", out commands)) {
stdout.printf ("Got option execute\n");
for (var i = 0; commands[i] != null; i++) {
if (commands[i] != "\0") {
window.add_tab_with_working_directory (working_directory, commands[i], new_tab);
}
}
} else if (options.lookup ("commandline", "^&ay", out command) && command != "\0") {
stdout.printf ("Got option commandline\n");
window.add_tab_with_working_directory (working_directory, command, new_tab);
} else if (new_tab || window.notebook.n_pages == 0) {
window.add_tab_with_working_directory (working_directory, null, new_tab);
}

if (options.lookup ("minimized", "b", out minimized) && minimized) {
stdout.printf ("Got option minimize\n");
window.minimize ();
} else {
} else if (!is_testing) {
stdout.printf ("presenting window\n");
window.present ();
}

if (is_first_window) {
if (is_first_window && !is_testing) {
/*
* This is very finicky. Bind size after present else set_titlebar gives us bad sizes
* Set maximize after height/width else window is min size on unmaximize
Expand All @@ -291,6 +347,7 @@ public class Terminal.Application : Gtk.Application {

saved_state.bind ("is-maximized", window, "maximized", SettingsBindFlags.SET);
}

return 0;
}

Expand All @@ -303,6 +360,7 @@ public class Terminal.Application : Gtk.Application {
}

public void close () {
stdout.printf (" App close \n");
foreach (var window in get_windows ()) {
window.close (); // if all windows is closed, the main loop will stop automatically.
}
Expand Down
27 changes: 17 additions & 10 deletions src/Widgets/TerminalWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,7 @@ namespace Terminal {
public const string[] ACCELS_ZOOM_OUT = { "<Control>minus", "<Control>KP_Subtract", null };

public int default_size;
const string SEND_PROCESS_FINISHED_BASH = "dbus-send --type=method_call " +
"--session --dest=io.elementary.terminal " +
"/io/elementary/terminal " +
"io.elementary.terminal.ProcessFinished " +
"string:$PANTHEON_TERMINAL_ID " +
"string:\"$(fc -nl -1 | cut -c 3-)\" " +
"int32:\$__bp_last_ret_value >/dev/null 2>&1";


/* Following strings are used to build RegEx for matching URIs */
const string USERCHARS = "-[:alnum:]";
Expand Down Expand Up @@ -698,16 +692,29 @@ namespace Terminal {
public void active_shell (string dir = GLib.Environment.get_current_dir ()) {
string shell = Application.settings.get_string ("shell");
string?[] envv = null;

if (shell == "")
stdout.printf (" Active shell");
if (shell == "") {
shell = Vte.get_user_shell ();
if (shell == "") {
return;
}
}

if (dir == "") {
debug ("Using fallback directory");
dir = "/";
}

envv = {
// Export ID so we can identify the terminal for which the process completion is reported
"PANTHEON_TERMINAL_ID=" + terminal_id,

// // Export callback command a BASH-specific variable, see "man bash" for details
// "PROMPT_COMMAND=" + SEND_PROCESS_FINISHED_BASH + Environment.get_variable ("PROMPT_COMMAND"),

// // ZSH callback command will be read from ZSH config file supplied by us, see data/
// Export callback command a BASH-specific variable, see "man bash" for details
"PROMPT_COMMAND=" + SEND_PROCESS_FINISHED_BASH + Environment.get_variable ("PROMPT_COMMAND"),
"PROMPT_COMMAND=" + Environment.get_variable ("PROMPT_COMMAND"),

// ZSH callback command will be read from ZSH config file supplied by us, see data/

Expand Down
14 changes: 7 additions & 7 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ app_test = executable(
vala_args: [ '--define', 'TESTS']
)

# test(
# 'Application',
# app_test,
# env: test_env,
# protocol: 'tap',
# depends: test_schemas
# )
test(
'Application',
app_test,
env: test_env,
protocol: 'tap',
depends: test_schemas
)
Loading
Loading