From 4cc4eb5ed033bb578f0d43e0c9ba840871a725f7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 26 Sep 2024 14:21:01 -0700 Subject: [PATCH] core: remove more hasdecls --- src/Surface.zig | 13 +++---------- src/apprt/glfw.zig | 18 +++++++++++++++++- src/apprt/gtk/Surface.zig | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 298bb6a0a..ed83b2af8 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -747,11 +747,7 @@ pub fn handleMessage(self: *Surface, msg: Message) !void { }, .report_title => |style| { - const title: ?[:0]const u8 = title: { - if (!@hasDecl(apprt.runtime.Surface, "getTitle")) break :title null; - break :title self.rt_surface.getTitle(); - }; - + const title: ?[:0]const u8 = self.rt_surface.getTitle(); const data = switch (style) { .csi_21_t => try std.fmt.allocPrint( self.alloc, @@ -901,7 +897,6 @@ fn modsChanged(self: *Surface, mods: input.Mods) void { /// Called when our renderer health state changes. fn updateRendererHealth(self: *Surface, health: renderer.Health) void { log.warn("renderer health status change status={}", .{health}); - if (!@hasDecl(apprt.runtime.Surface, "updateRendererHealth")) return; self.rt_surface.updateRendererHealth(health); } @@ -1158,10 +1153,8 @@ fn setSelection(self: *Surface, sel_: ?terminal.Selection) !void { // Check if our runtime supports the selection clipboard at all. // We can save a lot of work if it doesn't. - if (@hasDecl(apprt.runtime.Surface, "supportsClipboard")) { - if (!self.rt_surface.supportsClipboard(clipboard)) { - return; - } + if (!self.rt_surface.supportsClipboard(clipboard)) { + return; } const buf = self.io.terminal.screen.selectionString(self.alloc, .{ diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 4be6aaf89..b73aefced 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -411,7 +411,6 @@ pub const Surface = struct { /// Initialize the surface into the given self pointer. This gives a /// stable pointer to the destination that can be used for callbacks. pub fn init(self: *Surface, app: *App) !void { - // Create our window const win = glfw.Window.create( 640, @@ -715,6 +714,23 @@ pub const Surface = struct { self.window.setInputModeCursor(if (visible) .normal else .hidden); } + pub fn updateRendererHealth(self: *const Surface, health: renderer.Health) void { + // We don't support this in GLFW. + _ = self; + _ = health; + } + + pub fn supportsClipboard( + self: *const Surface, + clipboard_type: apprt.Clipboard, + ) bool { + _ = self; + return switch (clipboard_type) { + .standard => true, + .selection, .primary => comptime builtin.os.tag == .linux, + }; + } + /// Start an async clipboard request. pub fn clipboardRequest( self: *Surface, diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 657b6abf4..054eb675d 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -9,6 +9,7 @@ const configpkg = @import("../../config.zig"); const apprt = @import("../../apprt.zig"); const font = @import("../../font/main.zig"); const input = @import("../../input.zig"); +const renderer = @import("../../renderer.zig"); const terminal = @import("../../terminal/main.zig"); const CoreSurface = @import("../../Surface.zig"); const internal_os = @import("../../os/main.zig"); @@ -942,6 +943,19 @@ pub fn mouseOverLink(self: *Surface, uri_: ?[]const u8) void { self.url_widget = URLWidget.init(self, uriZ); } +pub fn supportsClipboard( + self: *const Surface, + clipboard_type: apprt.Clipboard, +) bool { + _ = self; + return switch (clipboard_type) { + .standard, + .selection, + .primary, + => true, + }; +} + pub fn clipboardRequest( self: *Surface, clipboard_type: apprt.Clipboard, @@ -1907,3 +1921,9 @@ pub fn present(self: *Surface) void { self.grabFocus(); } + +pub fn updateRendererHealth(self: *const Surface, health: renderer.Health) void { + // We don't support this in GTK. + _ = self; + _ = health; +}