Skip to content

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

tabs: a ghost of the tab follows the pointer once it is dragged out

Claude1882f2d2360a
diff --git a/src/Input.zig b/src/Input.zig
index 84d3da1..28392a0 100644
--- a/src/Input.zig
+++ b/src/Input.zig
@@ -230,6 +230,8 @@ move_snap: MoveSnap = .{},
tiling_grab: ?@import("tiling_grab.zig") = null,
/// An application being dragged from the start menu to the dock.
dock_drag: @import("dock_drag.zig") = .{},
+/// The dragged-out tab that follows the pointer (`tab_ghost.zig`).
+tab_ghost: @import("tab_ghost.zig") = .{},
/// Files from a client's drag, dropped on the dock's Trash.
trash_drop: @import("trash_drop.zig") = .{},
/// The last titlebar press, for double-click-to-maximize.
diff --git a/src/input/tab_drop.zig b/src/input/tab_drop.zig
index c278c6d..e5fcbf2 100644
--- a/src/input/tab_drop.zig
+++ b/src/input/tab_drop.zig
@@ -25,6 +25,7 @@ pub fn target(input: *Input, source: *Toplevel) ?Toplevel.DropTarget {
/// Keeps the drop marker on the strip under the pointer, and only there.
pub fn update(input: *Input, source: *Toplevel) void {
+ if (source.tab_drag.out) input.tab_ghost.follow(input, source) else input.tab_ghost.hide();
const found = target(input, source);
if (input.tab_drop_target) |previous| {
if (found == null or found.?.toplevel != previous) {
@@ -39,6 +40,7 @@ pub fn update(input: *Input, source: *Toplevel) void {
}
pub fn clear(input: *Input) void {
+ input.tab_ghost.hide();
if (input.tab_drop_target) |previous| previous.setTabDrop(null);
input.tab_drop_target = null;
}
diff --git a/src/tab_ghost.zig b/src/tab_ghost.zig
new file mode 100644
index 0000000..a006086
--- /dev/null
+++ b/src/tab_ghost.zig
@@ -0,0 +1,63 @@
+//! The tab that follows the pointer while it is dragged out of its window: a
+//! small themed tile with the tab's title, on the overlay above everything, so
+//! the drag reads as carrying the tab to another strip or out to a window of
+//! its own. It exists only while `Drag.out` holds; no input ever reaches it.
+const std = @import("std");
+const sn = @import("node.zig");
+const ui = @import("ui");
+const Input = @import("Input.zig");
+const Toplevel = @import("Toplevel.zig");
+const PanelBuffer = @import("panel_buffer.zig").PanelBuffer;
+const Self = @This();
+
+const width = 200;
+const height = 34;
+node: ?*sn.Buffer = null,
+
+fn ignoreInput(_: *sn.Buffer, _: *f64, _: *f64) callconv(.c) bool {
+ return false;
+}
+
+/// Shows the ghost of `source`'s dragged tab under the pointer, making it
+/// first if needed.
+pub fn follow(self: *Self, input: *Input, source: *Toplevel) void {
+ if (self.node == null) self.create(input, source);
+ if (self.node) |node| node.node.setPosition(
+ @intFromFloat(@floor(input.cursor.x - 24)),
+ @intFromFloat(@floor(input.cursor.y - height / 2)),
+ );
+}
+
+pub fn hide(self: *Self) void {
+ if (self.node) |node| node.node.destroy();
+ self.node = null;
+}
+
+fn create(self: *Self, input: *Input, source: *Toplevel) void {
+ var storage: [@import("window_tabs.zig").max_tabs]@import("chrome_tabs.zig").Tab = undefined;
+ const strip = source.tabStrip(&storage);
+ const title = for (strip.tabs) |t| {
+ if (t.id == source.tab_drag.id) break t.title;
+ } else "";
+ const scale = if (source.render_scale > 0) source.render_scale else 1;
+ const buffer = PanelBuffer.create(width, height, scale) catch return;
+ defer buffer.base.drop();
+ const pal = ui.theme.shellPalette();
+ var r = ui.paint.Renderer.init(buffer.pixels, buffer.width, buffer.height, scale);
+ r.palette = pal;
+ var bg = pal.window_bg;
+ bg[3] = 0.95;
+ r.fillRect(0, 0, width, height, .{ .color = bg, .radius = 10, .border_width = 1.5, .border_color = pal.accent });
+ r.drawText(14, 0, width - 28, height, .{
+ .content = title,
+ .font_size = ui.theme.global.taskbar_title_size,
+ .color = pal.window_fg,
+ });
+ const node = input.server.overlay_tree.createSceneBuffer(null) catch return;
+ node.point_accepts_input = ignoreInput;
+ node.setFilterMode(.bilinear);
+ node.setBuffer(&buffer.base);
+ node.setDestSize(width, height);
+ node.node.raiseToTop();
+ self.node = node;
+}