Skip to content

Commit 96749bd

Browse files
committed
Gtk4 port
Signed-off-by: Michael Hofmann <mhofmann@redhat.com>
1 parent 1a3e988 commit 96749bd

5 files changed

Lines changed: 24 additions & 22 deletions

File tree

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ AM_CPPFLAGS = $(TERMDEPS_CFLAGS)
44

55
AM_CFLAGS = -Wall -Wno-discarded-qualifiers -Wno-pointer-sign -Wno-unused-but-set-variable -Wno-unused-variable
66

7-
VALAFLAGS = --pkg=gtk+-3.0 --pkg=vte-2.91 --pkg=pango --pkg=posix --enable-checking
7+
VALAFLAGS = --pkg=gtk4 --pkg=vte-2.91-gtk4 --pkg=pango --pkg=posix --enable-checking
88

99
# the terminal
1010

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ AM_SILENT_RULES([yes])
1313
AM_PROG_VALAC([0.14.0])
1414
AM_PROG_CC_C_O
1515

16-
PKG_CHECK_MODULES(TERMDEPS, [gtk+-3.0 vte-2.91 >= 0.66.0])
16+
PKG_CHECK_MODULES(TERMDEPS, [gtk4 vte-2.91-gtk4 >= 0.66.0])
1717

1818
AC_CONFIG_FILES([Makefile])
1919

packit.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ downstream_package_name: simple-term
88
jobs:
99
- job: copr_build
1010
trigger: pull_request
11-
targets: [fedora-all]
11+
targets: [fedora-37, fedora-38, fedora-rawhide]
1212

1313
- job: copr_build
1414
trigger: commit
1515
branch: main
16-
targets: [fedora-all]
16+
targets: [fedora-37, fedora-38, fedora-rawhide]
1717
owner: mh21
1818
project: simple-term-latest
1919

2020
- job: copr_build
2121
trigger: release
22-
targets: [fedora-all]
22+
targets: [fedora-37, fedora-38, fedora-rawhide]
2323
owner: mh21
2424
project: simple-term

simple-term.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Source0: https://github.com/mh21/simple-term/archive/refs/tags/v%{version}.tar.g
1010

1111
BuildRequires: gnome-common
1212
BuildRequires: vala
13-
BuildRequires: gtk3-devel
14-
BuildRequires: vte291-devel
13+
BuildRequires: gtk4-devel
14+
BuildRequires: vte291-gtk4-devel
1515

1616
%description
1717
Simple vte-based terminal

simple-term.vala

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,29 @@ class TerminalWindow : Gtk.Window
3434
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_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"])?";
3535
private int link_tag;
3636

37-
private const Gdk.ModifierType key_mask = Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK |
37+
private const Gdk.ModifierType key_mask = Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.ALT_MASK |
3838
Gdk.ModifierType.SUPER_MASK | Gdk.ModifierType.HYPER_MASK | Gdk.ModifierType.META_MASK;
3939

4040
public TerminalWindow(Gtk.Application app, string[] command, string? title,
41-
string? font, string fg, string bg, string palette, string? role)
41+
string? font, string fg, string bg, string palette)
4242
{
4343
Object(application: app);
4444

4545
this.title = title != null ? title : string.joinv(" ", command);
4646
this.font = font;
4747

4848
terminal = new Vte.Terminal();
49-
add(terminal);
49+
set_child(terminal);
5050

5151
terminal.child_exited.connect(() => { destroy(); });
5252
terminal.decrease_font_size.connect(decrease_font_size_cb);
5353
terminal.increase_font_size.connect(increase_font_size_cb);
5454
terminal.window_title_changed.connect(window_title_changed_cb);
55+
/*
5556
terminal.key_press_event.connect(key_press_event_cb);
5657
terminal.button_press_event.connect(button_press_event_cb);
5758
terminal.drag_data_received.connect(drag_data_received_cb);
59+
*/
5860

5961
terminal.set_audible_bell(false);
6062
terminal.set_cursor_blink_mode(Vte.CursorBlinkMode.SYSTEM);
@@ -69,9 +71,6 @@ class TerminalWindow : Gtk.Window
6971
if (font != null)
7072
terminal.set_font(Pango.FontDescription.from_string(this.font));
7173

72-
if (role != null)
73-
this.set_role(role);
74-
7574
try {
7675
var regex = new Vte.Regex.for_match(link_expr, -1, PCRE2_MULTILINE);
7776
link_tag = terminal.match_add_regex(regex, 0);
@@ -81,9 +80,11 @@ class TerminalWindow : Gtk.Window
8180
// ignored
8281
}
8382

83+
/*
8484
Gtk.drag_dest_set(terminal, Gtk.DestDefaults.ALL, {}, Gdk.DragAction.COPY);
8585
Gtk.drag_dest_add_uri_targets(terminal); // prefer URIs to text
8686
Gtk.drag_dest_add_text_targets(terminal);
87+
*/
8788

8889
try {
8990
terminal.spawn_sync(Vte.PtyFlags.DEFAULT,
@@ -99,10 +100,10 @@ class TerminalWindow : Gtk.Window
99100
Idle.add(() => { destroy(); return false; });
100101
}
101102

102-
show_all();
103+
present();
103104
}
104105

105-
private static Gdk.RGBA? get_color(string str)
106+
private static Gdk.RGBA? parse_color(string str)
106107
{
107108
var color = Gdk.RGBA();
108109
if (!color.parse(str)) {
@@ -133,7 +134,7 @@ class TerminalWindow : Gtk.Window
133134
if (editor == null || editor[0] == '\0')
134135
editor = "vi";
135136
new TerminalWindow(this.get_application(), { editor, file.get_path() }, null,
136-
this.font, this.fg, this.bg, this.palette, "scrollback-edit");
137+
this.font, this.fg, this.bg, this.palette);
137138
// after 10 seconds the editor should have opened the file, remove
138139
// it from the filesystem again
139140
Timeout.add_seconds(10, () => { file.delete_async.begin(); return false; });
@@ -143,6 +144,7 @@ class TerminalWindow : Gtk.Window
143144
}
144145
}
145146

147+
/*
146148
public override bool delete_event(Gdk.EventAny event)
147149
{
148150
var pty = terminal.get_pty();
@@ -165,6 +167,7 @@ class TerminalWindow : Gtk.Window
165167
dialog.destroy();
166168
return result != Gtk.ResponseType.ACCEPT;
167169
}
170+
*/
168171

169172
private void decrease_font_size_cb()
170173
{
@@ -181,6 +184,7 @@ class TerminalWindow : Gtk.Window
181184
set_title(terminal.get_window_title());
182185
}
183186

187+
/*
184188
private bool button_press_event_cb(Gdk.EventButton event)
185189
{
186190
if (((event.state & key_mask) == Gdk.ModifierType.CONTROL_MASK) && (event.button == 1)) {
@@ -239,6 +243,7 @@ class TerminalWindow : Gtk.Window
239243
}
240244
Gtk.drag_finish(context, true, false, time);
241245
}
246+
*/
242247

243248
public void update_colors(string fg, string bg, string palette)
244249
{
@@ -248,8 +253,8 @@ class TerminalWindow : Gtk.Window
248253

249254
Gdk.RGBA[] colors = null;
250255
foreach (var color in palette.split(","))
251-
colors += get_color(color);
252-
terminal.set_colors(get_color(fg), get_color(bg), colors);
256+
colors += parse_color(color);
257+
terminal.set_colors(parse_color(fg), parse_color(bg), colors);
253258
}
254259
}
255260

@@ -270,7 +275,6 @@ class Application: Gtk.Application
270275
string fg = "black";
271276
string bg = "#ffffdd";
272277
string palette = "#000000,#aa0000,#00aa00,#aa5400,#0000aa,#aa00aa,#00aaaa,#aaaaaa,#545454,#ff5454,#54ff54,#ffff54,#5454ff,#ff54ff,#54ffff,#ffffff";
273-
string? role = null;
274278
bool update_colors = false;
275279

276280
for (int i = 1; i < argv.length; ++i) {
@@ -290,8 +294,6 @@ class Application: Gtk.Application
290294
} else if (argv[i] == "-e") {
291295
command = argv[i + 1:argv.length];
292296
i = argv.length - 1;
293-
} else if (argv[i] == "-role") {
294-
role = argv[++i];
295297
} else if (argv[i] == "-update") {
296298
update_colors = true;
297299
}
@@ -315,7 +317,7 @@ class Application: Gtk.Application
315317
command = { shell };
316318
}
317319

318-
new TerminalWindow(this, command, title, font, fg, bg, palette, role);
320+
new TerminalWindow(this, command, title, font, fg, bg, palette);
319321
return 0;
320322
}
321323

0 commit comments

Comments
 (0)