From 96749bdc06f572e32938db4addf7a1764977be83 Mon Sep 17 00:00:00 2001 From: Michael Hofmann Date: Tue, 18 Apr 2023 18:07:32 +0200 Subject: [PATCH] Gtk4 port Signed-off-by: Michael Hofmann --- Makefile.am | 2 +- configure.ac | 2 +- packit.yml | 6 +++--- simple-term.spec | 4 ++-- simple-term.vala | 32 +++++++++++++++++--------------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Makefile.am b/Makefile.am index 536ecb5..573b324 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,7 +4,7 @@ AM_CPPFLAGS = $(TERMDEPS_CFLAGS) AM_CFLAGS = -Wall -Wno-discarded-qualifiers -Wno-pointer-sign -Wno-unused-but-set-variable -Wno-unused-variable -VALAFLAGS = --pkg=gtk+-3.0 --pkg=vte-2.91 --pkg=pango --pkg=posix --enable-checking +VALAFLAGS = --pkg=gtk4 --pkg=vte-2.91-gtk4 --pkg=pango --pkg=posix --enable-checking # the terminal diff --git a/configure.ac b/configure.ac index 4fe50ec..b732650 100644 --- a/configure.ac +++ b/configure.ac @@ -13,7 +13,7 @@ AM_SILENT_RULES([yes]) AM_PROG_VALAC([0.14.0]) AM_PROG_CC_C_O -PKG_CHECK_MODULES(TERMDEPS, [gtk+-3.0 vte-2.91 >= 0.66.0]) +PKG_CHECK_MODULES(TERMDEPS, [gtk4 vte-2.91-gtk4 >= 0.66.0]) AC_CONFIG_FILES([Makefile]) diff --git a/packit.yml b/packit.yml index 294076b..af82b7f 100644 --- a/packit.yml +++ b/packit.yml @@ -8,17 +8,17 @@ downstream_package_name: simple-term jobs: - job: copr_build trigger: pull_request - targets: [fedora-all] + targets: [fedora-37, fedora-38, fedora-rawhide] - job: copr_build trigger: commit branch: main - targets: [fedora-all] + targets: [fedora-37, fedora-38, fedora-rawhide] owner: mh21 project: simple-term-latest - job: copr_build trigger: release - targets: [fedora-all] + targets: [fedora-37, fedora-38, fedora-rawhide] owner: mh21 project: simple-term diff --git a/simple-term.spec b/simple-term.spec index e9fb4b2..e109b7d 100644 --- a/simple-term.spec +++ b/simple-term.spec @@ -10,8 +10,8 @@ Source0: https://github.com/mh21/simple-term/archive/refs/tags/v%{version}.tar.g BuildRequires: gnome-common BuildRequires: vala -BuildRequires: gtk3-devel -BuildRequires: vte291-devel +BuildRequires: gtk4-devel +BuildRequires: vte291-gtk4-devel %description Simple vte-based terminal diff --git a/simple-term.vala b/simple-term.vala index 519010b..f9a2082 100644 --- a/simple-term.vala +++ b/simple-term.vala @@ -34,11 +34,11 @@ class TerminalWindow : Gtk.Window private const string link_expr = "(((file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?(/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"])?"; private int link_tag; - private const Gdk.ModifierType key_mask = Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK | + private const Gdk.ModifierType key_mask = Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.ALT_MASK | Gdk.ModifierType.SUPER_MASK | Gdk.ModifierType.HYPER_MASK | Gdk.ModifierType.META_MASK; public TerminalWindow(Gtk.Application app, string[] command, string? title, - string? font, string fg, string bg, string palette, string? role) + string? font, string fg, string bg, string palette) { Object(application: app); @@ -46,15 +46,17 @@ class TerminalWindow : Gtk.Window this.font = font; terminal = new Vte.Terminal(); - add(terminal); + set_child(terminal); terminal.child_exited.connect(() => { destroy(); }); terminal.decrease_font_size.connect(decrease_font_size_cb); terminal.increase_font_size.connect(increase_font_size_cb); terminal.window_title_changed.connect(window_title_changed_cb); + /* terminal.key_press_event.connect(key_press_event_cb); terminal.button_press_event.connect(button_press_event_cb); terminal.drag_data_received.connect(drag_data_received_cb); + */ terminal.set_audible_bell(false); terminal.set_cursor_blink_mode(Vte.CursorBlinkMode.SYSTEM); @@ -69,9 +71,6 @@ class TerminalWindow : Gtk.Window if (font != null) terminal.set_font(Pango.FontDescription.from_string(this.font)); - if (role != null) - this.set_role(role); - try { var regex = new Vte.Regex.for_match(link_expr, -1, PCRE2_MULTILINE); link_tag = terminal.match_add_regex(regex, 0); @@ -81,9 +80,11 @@ class TerminalWindow : Gtk.Window // ignored } + /* Gtk.drag_dest_set(terminal, Gtk.DestDefaults.ALL, {}, Gdk.DragAction.COPY); Gtk.drag_dest_add_uri_targets(terminal); // prefer URIs to text Gtk.drag_dest_add_text_targets(terminal); + */ try { terminal.spawn_sync(Vte.PtyFlags.DEFAULT, @@ -99,10 +100,10 @@ class TerminalWindow : Gtk.Window Idle.add(() => { destroy(); return false; }); } - show_all(); + present(); } - private static Gdk.RGBA? get_color(string str) + private static Gdk.RGBA? parse_color(string str) { var color = Gdk.RGBA(); if (!color.parse(str)) { @@ -133,7 +134,7 @@ class TerminalWindow : Gtk.Window if (editor == null || editor[0] == '\0') editor = "vi"; new TerminalWindow(this.get_application(), { editor, file.get_path() }, null, - this.font, this.fg, this.bg, this.palette, "scrollback-edit"); + this.font, this.fg, this.bg, this.palette); // after 10 seconds the editor should have opened the file, remove // it from the filesystem again Timeout.add_seconds(10, () => { file.delete_async.begin(); return false; }); @@ -143,6 +144,7 @@ class TerminalWindow : Gtk.Window } } + /* public override bool delete_event(Gdk.EventAny event) { var pty = terminal.get_pty(); @@ -165,6 +167,7 @@ class TerminalWindow : Gtk.Window dialog.destroy(); return result != Gtk.ResponseType.ACCEPT; } + */ private void decrease_font_size_cb() { @@ -181,6 +184,7 @@ class TerminalWindow : Gtk.Window set_title(terminal.get_window_title()); } + /* private bool button_press_event_cb(Gdk.EventButton event) { if (((event.state & key_mask) == Gdk.ModifierType.CONTROL_MASK) && (event.button == 1)) { @@ -239,6 +243,7 @@ class TerminalWindow : Gtk.Window } Gtk.drag_finish(context, true, false, time); } + */ public void update_colors(string fg, string bg, string palette) { @@ -248,8 +253,8 @@ class TerminalWindow : Gtk.Window Gdk.RGBA[] colors = null; foreach (var color in palette.split(",")) - colors += get_color(color); - terminal.set_colors(get_color(fg), get_color(bg), colors); + colors += parse_color(color); + terminal.set_colors(parse_color(fg), parse_color(bg), colors); } } @@ -270,7 +275,6 @@ class Application: Gtk.Application string fg = "black"; string bg = "#ffffdd"; string palette = "#000000,#aa0000,#00aa00,#aa5400,#0000aa,#aa00aa,#00aaaa,#aaaaaa,#545454,#ff5454,#54ff54,#ffff54,#5454ff,#ff54ff,#54ffff,#ffffff"; - string? role = null; bool update_colors = false; for (int i = 1; i < argv.length; ++i) { @@ -290,8 +294,6 @@ class Application: Gtk.Application } else if (argv[i] == "-e") { command = argv[i + 1:argv.length]; i = argv.length - 1; - } else if (argv[i] == "-role") { - role = argv[++i]; } else if (argv[i] == "-update") { update_colors = true; } @@ -315,7 +317,7 @@ class Application: Gtk.Application command = { shell }; } - new TerminalWindow(this, command, title, font, fg, bg, palette, role); + new TerminalWindow(this, command, title, font, fg, bg, palette); return 0; }