Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

editor: New Window action (stage 3)

Claude5fbcc75478a0
diff --git a/po/de.po b/po/de.po
index 16746b9..d98f676 100644
--- a/po/de.po
+++ b/po/de.po
@@ -6687,6 +6687,10 @@ msgstr "Kabel- und Funkverbindungen."
msgid "Wireless connections"
msgstr "Funkverbindungen"
+#: src/editor/app.zig
+msgid "New Window"
+msgstr "Neues Fenster"
+
#: src/editor/app.zig
msgid "Word Wrap"
msgstr "Zeilenumbruch"
diff --git a/po/es.po b/po/es.po
index 02d087f..999fd63 100644
--- a/po/es.po
+++ b/po/es.po
@@ -6684,6 +6684,10 @@ msgstr "Conexiones cableadas e inalámbricas."
msgid "Wireless connections"
msgstr "Conexiones inalámbricas"
+#: src/editor/app.zig
+msgid "New Window"
+msgstr "Nueva ventana"
+
#: src/editor/app.zig
msgid "Word Wrap"
msgstr "Ajuste de línea"
diff --git a/po/fr.po b/po/fr.po
index 6ac21bb..189094e 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -6687,6 +6687,10 @@ msgstr "Connexions filaires et sans fil."
msgid "Wireless connections"
msgstr "Connexions sans fil"
+#: src/editor/app.zig
+msgid "New Window"
+msgstr "Nouvelle fenêtre"
+
#: src/editor/app.zig
msgid "Word Wrap"
msgstr "Retour à la ligne"
diff --git a/po/pt_BR.po b/po/pt_BR.po
index 3f31199..d203c60 100644
--- a/po/pt_BR.po
+++ b/po/pt_BR.po
@@ -6684,6 +6684,10 @@ msgstr "Conexões cabeadas e sem fio."
msgid "Wireless connections"
msgstr "Conexões sem fio"
+#: src/editor/app.zig
+msgid "New Window"
+msgstr "Nova janela"
+
#: src/editor/app.zig
msgid "Word Wrap"
msgstr "Quebra de linha"
diff --git a/po/rediwm.pot b/po/rediwm.pot
index 4559f0c..2d478ba 100644
--- a/po/rediwm.pot
+++ b/po/rediwm.pot
@@ -7848,6 +7848,10 @@ msgstr ""
msgid "Wireless connections"
msgstr ""
+#: src/editor/app.zig
+msgid "New Window"
+msgstr ""
+
#: src/editor/app.zig
msgid "Word Wrap"
msgstr ""
diff --git a/po/ru.po b/po/ru.po
index bee006b..d88a217 100644
--- a/po/ru.po
+++ b/po/ru.po
@@ -6690,6 +6690,10 @@ msgstr "Проводные и беспроводные подключения."
msgid "Wireless connections"
msgstr "Беспроводные подключения"
+#: src/editor/app.zig
+msgid "New Window"
+msgstr "Новое окно"
+
#: src/editor/app.zig
msgid "Word Wrap"
msgstr "Перенос строк"
diff --git a/src/editor/app.zig b/src/editor/app.zig
index 14b5e0b..c6734d4 100644
--- a/src/editor/app.zig
+++ b/src/editor/app.zig
@@ -42,8 +42,8 @@ const Status = struct {
};
/// Stand-in for the position of a cursor too far from the view to measure.
pub const far: c_int = 1_000_000 * 1024;
-pub const Action = enum { new, open, open_recent, save, save_as, find, replace, wrap };
-pub const labels = [_]i18n.Message{ i18n.msg("New"), i18n.msg("Open"), i18n.msg("Open Recent"), i18n.msg("Save"), i18n.msg("Save As"), i18n.msg("Find"), i18n.msg("Replace"), i18n.msg("Word Wrap") };
+pub const Action = enum { new, new_window, open, open_recent, save, save_as, find, replace, wrap };
+pub const labels = [_]i18n.Message{ i18n.msg("New"), i18n.msg("New Window"), i18n.msg("Open"), i18n.msg("Open Recent"), i18n.msg("Save"), i18n.msg("Save As"), i18n.msg("Find"), i18n.msg("Replace"), i18n.msg("Word Wrap") };
/// The menu row whose submenu lists the recent files.
pub const recent_row = @intFromEnum(Action.open_recent);
pub const Tab = struct {
@@ -83,6 +83,8 @@ pub const App = struct {
dirty: bool = true,
title_changed: bool = true,
closed: bool = false,
+ /// Set by the New Window action; the event loop opens the window.
+ new_window: bool = false,
ctrl: bool = false,
shift: bool = false,
alt: bool = false,
diff --git a/src/editor/app_files.zig b/src/editor/app_files.zig
index 399b532..478bf35 100644
--- a/src/editor/app_files.zig
+++ b/src/editor/app_files.zig
@@ -180,6 +180,7 @@ pub fn finishClose(self: *App) void {
pub fn act(self: *App, action: Action) void {
switch (action) {
.new => self.newTab() catch |err| self.failure(err),
+ .new_window => self.new_window = true,
.open => self.choose(false),
.open_recent => {}, // the menu opens its submenu; nothing to run
.save => self.save(false),
diff --git a/src/editor/app_input.zig b/src/editor/app_input.zig
index 4b73e02..8619ae9 100644
--- a/src/editor/app_input.zig
+++ b/src/editor/app_input.zig
@@ -272,7 +272,7 @@ pub fn handleKey(self: *App, sym: u32, utf8: []const u8) void {
}
if (self.ctrl) switch (sym) {
c.XKB_KEY_n, c.XKB_KEY_N, c.XKB_KEY_t, c.XKB_KEY_T => {
- self.act(.new);
+ self.act(if (self.shift and (sym == c.XKB_KEY_n or sym == c.XKB_KEY_N)) .new_window else .new);
return;
},
c.XKB_KEY_o, c.XKB_KEY_O => {
diff --git a/src/editor/app_paint.zig b/src/editor/app_paint.zig
index 00e72c7..4be485a 100644
--- a/src/editor/app_paint.zig
+++ b/src/editor/app_paint.zig
@@ -172,7 +172,7 @@ pub fn menuBox(self: *const App) menu.Rect {
pub fn menuRow(self: *const App, i: usize) menu.Rect {
const box = self.menuBox();
- const separators: usize = @as(usize, if (i >= 3) 1 else 0) + @as(usize, if (i >= 5) 1 else 0);
+ const separators: usize = @as(usize, if (i >= 4) 1 else 0) + @as(usize, if (i >= 6) 1 else 0);
return .{ .x = box.x + menu.padding, .y = box.y + @as(f64, @floatFromInt(menu.padding + i * menu.row_height + separators * menu.separator_space)), .w = box.w - 2 * menu.padding, .h = menu.row_height };
}
@@ -184,14 +184,14 @@ pub fn menuHit(self: *const App, x: f64, y: f64) ?usize {
pub fn paintMenu(self: *App, cr: *c.cairo_t) void {
menu.frame(cr, self.menuBox(), true);
const IconId = @import("ui").layout.IconId;
- const icons = [_]?IconId{ .plus, .open, .clock, .save, .save, .search, .search, if (self.wrap) .checkmark else null };
- const hints = [_]?[]const u8{ "CTRL+N", "CTRL+O", null, "CTRL+S", "CTRL+SHIFT+S", "CTRL+F", "CTRL+H", null };
+ const icons = [_]?IconId{ .plus, .plus, .open, .clock, .save, .save, .search, .search, if (self.wrap) .checkmark else null };
+ const hints = [_]?[]const u8{ "CTRL+N", "CTRL+SHIFT+N", "CTRL+O", null, "CTRL+S", "CTRL+SHIFT+S", "CTRL+F", "CTRL+H", null };
for (labels, 0..) |label, i| menu.row(cr, self.menuRow(i), .{
.label = label.get(),
.hint = hints[i],
.icon = icons[i],
.selected = self.menu_selected == i,
- .separator = i == 3 or i == 5,
+ .separator = i == 4 or i == 6,
.disabled = i == recent_row and !self.recentEnabled(),
}, true);
// The chevron says the row opens a submenu.
diff --git a/src/editor/main.zig b/src/editor/main.zig
index fb38f2d..1dccf76 100644
--- a/src/editor/main.zig
+++ b/src/editor/main.zig
@@ -187,6 +187,9 @@ pub const Buffer = struct {
};
/// What every window of the process shares when it is created.
+/// What the poll array below has room for: three fixed entries plus a few per window.
+const max_windows = 24;
+
pub const Setup = struct { io: std.Io, environ: std.process.Environ, force_csd: bool };
pub fn run(init: std.process.Init, paths: []const [:0]const u8, instance: *@import("instance.zig").Instance, initial_token: []const u8) !void {
@@ -246,6 +249,17 @@ pub fn run(init: std.process.Init, paths: []const [:0]const u8, instance: *@impo
index += 1;
}
if (windows.items.len == 0) break;
+ // New Window: opened here, outside the loop above, so the list is not
+ // changing under it. The new window starts with one empty tab.
+ for (windows.items) |window| {
+ if (!window.app.new_window) continue;
+ window.app.new_window = false;
+ if (windows.items.len >= max_windows) continue;
+ if (Client.create(display, setup, false, &.{})) |created| {
+ windows.append(a, created) catch created.destroy();
+ } else |err| std.log.warn("rediwm-editor: cannot open a window: {}", .{err});
+ break; // the list may have grown; one a turn is plenty
+ }
while (!display.prepareRead()) {
if (display.dispatchPending() != .SUCCESS) return error.DisplayFailed;