Skip to content

Commit

Permalink
gtk: fix context menu computed location (#5710)
Browse files Browse the repository at this point in the history
When a tab bar is displayed, the context menu opened with right click is
offset from the cursor.

This was due to using the incorrect coordinate space for describing
where to draw the context menu.


[gtk_popover_set_pointing_to](https://docs.gtk.org/gtk4/method.Popover.set_pointing_to.html)
uses the coordinate space of the popover's parent, however we used the
active window's coordinate space which was noticeably different when the
tab bar is visible.

Before:
![Screenshot_12-Feb_22-39-07_com mitchellh
ghostty](https://github.com/user-attachments/assets/5263dd9d-f3ab-44f6-baf2-7208d3d3bd01)
After:
![Screenshot_12-Feb_22-41-41_com mitchellh
ghostty-debug](https://github.com/user-attachments/assets/8d3e8bbd-af4e-43a6-a52d-6601a0b66ece)
  • Loading branch information
pluiedev authored Feb 12, 2025
2 parents 338a07e + b1ae7ee commit 76ab671
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/apprt/gtk/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1270,10 +1270,12 @@ fn showContextMenu(self: *Surface, x: f32, y: f32) void {
return;
};

// Convert surface coordinate into coordinate space of the
// context menu's parent
var point: c.graphene_point_t = .{ .x = x, .y = y };
if (c.gtk_widget_compute_point(
self.primaryWidget(),
@ptrCast(window.window),
c.gtk_widget_get_parent(@ptrCast(window.context_menu)),
&c.GRAPHENE_POINT_INIT(point.x, point.y),
@ptrCast(&point),
) == 0) {
Expand Down

0 comments on commit 76ab671

Please sign in to comment.