Skip to content

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

editor: menu button at the end of the in-content tab strip when self-decorated

Claudedff5540ab7c0
diff --git a/src/editor/app_controls.zig b/src/editor/app_controls.zig
index af56fdc..2a73890 100644
--- a/src/editor/app_controls.zig
+++ b/src/editor/app_controls.zig
@@ -62,7 +62,7 @@ fn nearestButton(self: *App, x: f64, y: f64) f32 {
);
nearest = @min(nearest, sample.distance);
}
- if (!self.has_titlebar and !self.strip_in_titlebar) {
+ if (!self.strip_in_titlebar) {
const box = self.menuButtonBox();
const sample = button.sampleProximity(
.{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) },
@@ -185,7 +185,7 @@ pub fn hoverTarget(self: *App) Hover {
if (self.find_open) if (self.searchHit(self.px, self.py)) |hit| return .{ .search = hit };
if (self.strip_in_titlebar) return .none;
if (self.newButtonBox().contains(self.px, self.py)) return .new;
- if (!self.has_titlebar and self.menuButtonBox().contains(self.px, self.py)) return .menu;
+ if (self.menuButtonBox().contains(self.px, self.py)) return .menu;
if (self.tabAt(self.px)) |i| if (self.tabCloseBox(i).contains(self.px, self.py)) return .{ .close = i };
return .none;
}
diff --git a/src/editor/app_input.zig b/src/editor/app_input.zig
index 8f8590e..4b73e02 100644
--- a/src/editor/app_input.zig
+++ b/src/editor/app_input.zig
@@ -112,7 +112,7 @@ pub fn handleButton(self: *App, code: u32, pressed: bool) void {
}
if (self.py < 0) return;
if (self.py < self.topInset()) {
- if (!self.has_titlebar and self.menuButtonBox().contains(self.px, self.py)) {
+ if (self.menuButtonBox().contains(self.px, self.py)) {
self.toggleMenu(@as(f64, @floatFromInt(self.w)) - 8);
return;
}
@@ -221,7 +221,8 @@ pub fn handleKey(self: *App, sym: u32, utf8: []const u8) void {
return;
}
if (sym == c.XKB_KEY_F10 and !self.ctrl and !self.alt) {
- self.toggleMenu(self.menu_anchor);
+ // Under the compositor's titlebar the menu hangs from the leading button.
+ self.toggleMenu(if (self.strip_in_titlebar) self.menu_anchor else @as(f64, @floatFromInt(self.w)) - 8);
return;
}
if (self.menu_open and self.sub_selected != null) {
diff --git a/src/editor/app_paint.zig b/src/editor/app_paint.zig
index 457bc06..00e72c7 100644
--- a/src/editor/app_paint.zig
+++ b/src/editor/app_paint.zig
@@ -131,7 +131,7 @@ pub fn paintCaret(self: *App, cr: *c.cairo_t) void {
}
pub fn tabRight(self: *const App) f64 {
- return @as(f64, @floatFromInt(self.w)) - @as(f64, if (self.has_titlebar) 40 else 80);
+ return @as(f64, @floatFromInt(self.w)) - 80;
}
pub fn dismissMenu(self: *App) void {
@@ -164,7 +164,7 @@ pub fn menuBox(self: *const App) menu.Rect {
const height = labels.len * menu.row_height + 2 * menu.padding + 2 * menu.separator_space;
return .{
.x = std.math.clamp(self.menu_anchor - menu.width, 6, @max(6, @as(f64, @floatFromInt(self.w)) - menu.width - 6)),
- .y = @min(if (self.has_titlebar or self.strip_in_titlebar) @as(f64, 6) else top + 4, @max(6, @as(f64, @floatFromInt(self.h)) - height - 6)),
+ .y = @min(if (self.strip_in_titlebar) @as(f64, 6) else top + 4, @max(6, @as(f64, @floatFromInt(self.h)) - height - 6)),
.w = menu.width,
.h = height,
};
@@ -251,7 +251,7 @@ fn paintStrip(self: *App, cr: *c.cairo_t) void {
}
c.cairo_restore(cr);
self.paintIcon(cr, self.newButtonBox(), .plus, tr("New tab"), false);
- if (!self.has_titlebar) self.paintIcon(cr, self.menuButtonBox(), .more, tr("Menu"), self.menu_open);
+ self.paintIcon(cr, self.menuButtonBox(), .more, tr("Menu"), self.menu_open);
}
pub fn render(self: *App, cr: *c.cairo_t) void {
diff --git a/src/editor/client_input.zig b/src/editor/client_input.zig
index c05357c..ef04cd5 100644
--- a/src/editor/client_input.zig
+++ b/src/editor/client_input.zig
@@ -149,11 +149,6 @@ pub fn toggleMaximized(self: *Client) void {
}
pub fn handleTitlebarClick(self: *Client) void {
- if (self.overHeaderButton(.menu)) {
- const r = self.headerButton(.menu);
- self.app.toggleMenu(r.x + r.w);
- return;
- }
self.app.dismissMenu();
if (self.overHeaderButton(.close)) {
self.app.requestClose();
diff --git a/src/editor/client_render.zig b/src/editor/client_render.zig
index bcf71f9..de8d43f 100644
--- a/src/editor/client_render.zig
+++ b/src/editor/client_render.zig
@@ -120,8 +120,8 @@ pub fn renderTitlebar(self: *Client, cr: *c.cairo_t, w: i32, h: i32) void {
c.cairo_line_to(cr, w_f, h_f - 0.5);
c.cairo_stroke(cr);
- const menu_rect = self.headerButton(.menu);
- self.app.menu_anchor = menu_rect.x + menu_rect.w;
+ // The menu button lives at the end of the tab strip below, not here.
+ const minimize_rect = self.headerButton(.minimize);
if (shell_ui.Layer.begin(cr, .{ .x = 16, .y = @floatCast((h_f - 20) / 2), .w = 20, .h = 20 })) |l| {
var layer = l;
layer.renderer.drawIcon(0, 0, 20, 20, .{ .id = .edit, .color = ui_theme.global.window_fg });
@@ -132,18 +132,12 @@ pub fn renderTitlebar(self: *Client, cr: *c.cairo_t, w: i32, h: i32) void {
const metrics = shell_ui.fontMetrics(cr, title_size);
shell_ui.setSource(cr, ui_theme.global.window_fg);
c.cairo_save(cr);
- c.cairo_rectangle(cr, 46, 0, @max(0, menu_rect.x - 54), h_f);
+ c.cairo_rectangle(cr, 46, 0, @max(0, minimize_rect.x - 54), h_f);
c.cairo_clip(cr);
shell_ui.drawText(cr, title, 46, (h_f + metrics.ascent - metrics.descent) / 2, title_size, true);
c.cairo_restore(cr);
- const divider = (menu_rect.x + menu_rect.w + self.headerButton(.minimize).x) / 2;
- shell_ui.setSource(cr, ui_theme.global.app_divider);
- c.cairo_set_line_width(cr, 1);
- c.cairo_move_to(cr, @floor(divider) + 0.5, h_f * 0.3);
- c.cairo_line_to(cr, @floor(divider) + 0.5, h_f * 0.7);
- c.cairo_stroke(cr);
- inline for (.{ HeaderControl.menu, HeaderControl.minimize, HeaderControl.maximize, HeaderControl.close }) |control| {
+ inline for (.{ HeaderControl.minimize, HeaderControl.maximize, HeaderControl.close }) |control| {
const r = self.headerButton(control);
if (shell_ui.Layer.begin(cr, r)) |l| {
var layer = l;