initial commit

This commit is contained in:
evertonstz
2026-01-15 10:53:00 -03:00
parent 2fd3efd6cd
commit 78a503491e
2 changed files with 61 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ const terminal = @import("../../../terminal/main.zig");
const CoreSurface = @import("../../../Surface.zig");
const gresource = @import("../build/gresource.zig");
const ext = @import("../ext.zig");
const gsettings = @import("../gsettings.zig");
const gtk_key = @import("../key.zig");
const ApprtSurface = @import("../Surface.zig");
const Common = @import("../class.zig").Common;
@@ -674,6 +675,11 @@ pub const Surface = extern struct {
/// The context for this surface (window, tab, or split)
context: apprt.surface.NewSurfaceContext = .window,
/// Whether primary paste (middle-click paste) is enabled via GNOME settings.
/// If null, the setting could not be read (non-GNOME system or schema missing).
/// If true, middle-click paste is enabled. If false, it's disabled.
gtk_enable_primary_paste: ?bool = null,
pub var offset: c_int = 0;
};
@@ -1511,12 +1517,10 @@ pub const Surface = extern struct {
const xft_dpi_scale = xft_scale: {
// gtk-xft-dpi is font DPI multiplied by 1024. See
// https://docs.gtk.org/gtk4/property.Settings.gtk-xft-dpi.html
const settings = gtk.Settings.getDefault() orelse break :xft_scale 1.0;
var value = std.mem.zeroes(gobject.Value);
defer value.unset();
_ = value.init(gobject.ext.typeFor(c_int));
settings.as(gobject.Object).getProperty("gtk-xft-dpi", &value);
const gtk_xft_dpi = value.getInt();
const gtk_xft_dpi = gsettings.readSetting(c_int, "gtk-xft-dpi") orelse {
log.warn("gtk-xft-dpi was not set, using default value", .{});
break :xft_scale 1.0;
};
// Use a value of 1.0 for the XFT DPI scale if the setting is <= 0
// See:
@@ -1767,6 +1771,10 @@ pub const Surface = extern struct {
priv.im_composing = false;
priv.im_len = 0;
// Read GNOME desktop interface settings for primary paste (middle-click)
// This is only relevant on Linux systems with GNOME settings available
priv.gtk_enable_primary_paste = gsettings.readSetting(bool, "gtk-enable-primary-paste");
// Set up to handle items being dropped on our surface. Files can be dropped
// from Nautilus and strings can be dropped from many programs. The order
// of these types matter.
@@ -2685,6 +2693,13 @@ pub const Surface = extern struct {
// Report the event
const button = translateMouseButton(gesture.as(gtk.GestureSingle).getCurrentButton());
// Check if middle button paste should be disabled based on GNOME settings
// If gtk_enable_primary_paste is explicitly false, skip processing middle button
if (button == .middle and priv.gtk_enable_primary_paste == false) {
return;
}
const consumed = consumed: {
const gtk_mods = event.getModifierState();
const mods = gtk_key.translateMods(gtk_mods);
@@ -2736,6 +2751,12 @@ pub const Surface = extern struct {
const gtk_mods = event.getModifierState();
const button = translateMouseButton(gesture.as(gtk.GestureSingle).getCurrentButton());
// Check if middle button paste should be disabled based on GNOME settings
// If gtk_enable_primary_paste is explicitly false, skip processing middle button
if (button == .middle and priv.gtk_enable_primary_paste == false) {
return;
}
const mods = gtk_key.translateMods(gtk_mods);
const consumed = surface.mouseButtonCallback(
.release,

View File

@@ -0,0 +1,34 @@
const std = @import("std");
const builtin = @import("builtin");
const gtk = @import("gtk");
const gobject = @import("gobject");
/// Reads a GTK setting using the GTK Settings API.
/// This automatically uses XDG Desktop Portal in Flatpak environments.
/// Returns null if not on a GTK-supported platform or if the setting cannot be read.
///
/// Supported platforms: Linux, FreeBSD
/// Supported types: bool, c_int
///
/// Example usage:
/// const enabled = readSetting(bool, "gtk-enable-primary-paste");
/// const dpi = readSetting(c_int, "gtk-xft-dpi");
pub fn readSetting(comptime T: type, key: [*:0]const u8) ?T {
// Only available on systems that use GTK (Linux, FreeBSD)
if (comptime builtin.os.tag != .linux and builtin.os.tag != .freebsd) return null;
const settings = gtk.Settings.getDefault() orelse return null;
// For bool and c_int, we use c_int as the underlying GObject type
// because GTK boolean properties are stored as integers
var value = gobject.ext.Value.new(c_int);
defer value.unset();
settings.as(gobject.Object).getProperty(key, &value);
return switch (T) {
bool => value.getInt() != 0,
c_int => value.getInt(),
else => @compileError("Unsupported type '" ++ @typeName(T) ++ "' for GTK setting. Supported types: bool, c_int"),
};
}