gtk: don't copy resize overlay

This commit is contained in:
Jeffrey C. Ollie
2025-02-01 10:48:51 -06:00
parent c5508e7d19
commit f0af9113df
2 changed files with 14 additions and 22 deletions

View File

@ -7,9 +7,6 @@ const Surface = @import("Surface.zig");
const log = std.log.scoped(.gtk);
/// Back reference to the surface we belong to
surface: ?*Surface = null,
/// If non-null this is the widget on the overlay that shows the size of the
/// surface when it is resized.
widget: ?*c.GtkWidget = null,
@ -26,10 +23,8 @@ first: bool = true,
/// Initialize the ResizeOverlay. This doesn't do anything more than save a
/// pointer to the surface that we are a part of as all of the widget creation
/// is done later.
pub fn init(surface: *Surface) ResizeOverlay {
return .{
.surface = surface,
};
pub fn init(self: *ResizeOverlay) void {
self.* = .{};
}
/// De-initialize the ResizeOverlay. This removes any pending idlers/timers that
@ -56,10 +51,7 @@ pub fn deinit(self: *ResizeOverlay) void {
///
/// If we're not configured to show the overlay, do nothing.
pub fn maybeShow(self: *ResizeOverlay) void {
const surface = self.surface orelse {
log.err("resize overlay configured without a surface", .{});
return;
};
const surface: *Surface = @alignCast(@fieldParentPtr("resize_overlay", self));
switch (surface.app.config.@"resize-overlay") {
.never => return,
@ -84,15 +76,12 @@ pub fn maybeShow(self: *ResizeOverlay) void {
/// Actually update the overlay widget. This should only be called from a GTK
/// idle handler.
fn gtkUpdate(ud: ?*anyopaque) callconv(.C) c.gboolean {
const self: *ResizeOverlay = @ptrCast(@alignCast(ud));
const self: *ResizeOverlay = @ptrCast(@alignCast(ud orelse return c.FALSE));
// No matter what our idler is complete with this callback
self.idler = null;
const surface = self.surface orelse {
log.err("resize overlay configured without a surface", .{});
return c.FALSE;
};
const surface: *Surface = @alignCast(@fieldParentPtr("resize_overlay", self));
const grid_size = surface.core_surface.size.grid();
var buf: [32]u8 = undefined;

View File

@ -266,8 +266,8 @@ pub const URLWidget = struct {
);
// Show it
c.gtk_overlay_add_overlay(@ptrCast(surface.overlay), left);
c.gtk_overlay_add_overlay(@ptrCast(surface.overlay), right);
c.gtk_overlay_add_overlay(surface.overlay, left);
c.gtk_overlay_add_overlay(surface.overlay, right);
return .{
.left = left,
@ -276,8 +276,8 @@ pub const URLWidget = struct {
}
pub fn deinit(self: *URLWidget, overlay: *c.GtkOverlay) void {
c.gtk_overlay_remove_overlay(@ptrCast(overlay), @ptrCast(self.left));
c.gtk_overlay_remove_overlay(@ptrCast(overlay), @ptrCast(self.right));
c.gtk_overlay_remove_overlay(overlay, @ptrCast(self.left));
c.gtk_overlay_remove_overlay(overlay, @ptrCast(self.right));
}
pub fn setText(self: *const URLWidget, str: [:0]const u8) void {
@ -329,7 +329,7 @@ gl_area: *c.GtkGLArea,
url_widget: ?URLWidget = null,
/// The overlay that shows resizing information.
resize_overlay: ResizeOverlay = .{},
resize_overlay: ResizeOverlay = undefined,
/// Whether or not the current surface is zoomed in (see `toggle_split_zoom`).
zoomed_in: bool = false,
@ -553,7 +553,7 @@ pub fn init(self: *Surface, app: *App, opts: Options) !void {
.container = .{ .none = {} },
.overlay = @ptrCast(overlay),
.gl_area = @ptrCast(gl_area),
.resize_overlay = ResizeOverlay.init(self),
.resize_overlay = undefined,
.title_text = null,
.core_surface = undefined,
.font_size = font_size,
@ -565,6 +565,9 @@ pub fn init(self: *Surface, app: *App, opts: Options) !void {
};
errdefer self.* = undefined;
// initialize the resize overlay
self.resize_overlay.init();
// Set our default mouse shape
try self.setMouseShape(.text);