mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Moved clipboard logic to copyOnMouseAction, created copy-on-right-click config
This commit is contained in:
@ -235,7 +235,8 @@ const DerivedConfig = struct {
|
|||||||
clipboard_trim_trailing_spaces: bool,
|
clipboard_trim_trailing_spaces: bool,
|
||||||
clipboard_paste_protection: bool,
|
clipboard_paste_protection: bool,
|
||||||
clipboard_paste_bracketed_safe: bool,
|
clipboard_paste_bracketed_safe: bool,
|
||||||
copy_on_select: configpkg.CopyOnSelect,
|
copy_on_select: configpkg.CopyOnMouseAction,
|
||||||
|
copy_on_right_click: configpkg.CopyOnMouseAction,
|
||||||
confirm_close_surface: configpkg.ConfirmCloseSurface,
|
confirm_close_surface: configpkg.ConfirmCloseSurface,
|
||||||
cursor_click_to_move: bool,
|
cursor_click_to_move: bool,
|
||||||
desktop_notifications: bool,
|
desktop_notifications: bool,
|
||||||
@ -297,6 +298,7 @@ const DerivedConfig = struct {
|
|||||||
.clipboard_paste_protection = config.@"clipboard-paste-protection",
|
.clipboard_paste_protection = config.@"clipboard-paste-protection",
|
||||||
.clipboard_paste_bracketed_safe = config.@"clipboard-paste-bracketed-safe",
|
.clipboard_paste_bracketed_safe = config.@"clipboard-paste-bracketed-safe",
|
||||||
.copy_on_select = config.@"copy-on-select",
|
.copy_on_select = config.@"copy-on-select",
|
||||||
|
.copy_on_right_click = config.@"copy-on-right-click",
|
||||||
.confirm_close_surface = config.@"confirm-close-surface",
|
.confirm_close_surface = config.@"confirm-close-surface",
|
||||||
.cursor_click_to_move = config.@"cursor-click-to-move",
|
.cursor_click_to_move = config.@"cursor-click-to-move",
|
||||||
.desktop_notifications = config.@"desktop-notifications",
|
.desktop_notifications = config.@"desktop-notifications",
|
||||||
@ -1405,20 +1407,7 @@ fn clipboardWrite(self: *const Surface, data: []const u8, loc: apprt.Clipboard)
|
|||||||
/// Set the selection contents.
|
/// Set the selection contents.
|
||||||
///
|
///
|
||||||
/// This must be called with the renderer mutex held.
|
/// This must be called with the renderer mutex held.
|
||||||
fn setSelection(self: *Surface, sel_: ?terminal.Selection) !void {
|
fn copyOnMouseAction(self: *Surface, sel: terminal.Selection, action: configpkg.CopyOnMouseAction) !void {
|
||||||
const prev_ = self.io.terminal.screen.selection;
|
|
||||||
try self.io.terminal.screen.select(sel_);
|
|
||||||
|
|
||||||
// If copy on select is false then exit early.
|
|
||||||
if (self.config.copy_on_select == .false) return;
|
|
||||||
|
|
||||||
// Set our selection clipboard. If the selection is cleared we do not
|
|
||||||
// clear the clipboard. If the selection is set, we only set the clipboard
|
|
||||||
// again if it changed, since setting the clipboard can be an expensive
|
|
||||||
// operation.
|
|
||||||
const sel = sel_ orelse return;
|
|
||||||
if (prev_) |prev| if (sel.eql(prev)) return;
|
|
||||||
|
|
||||||
const buf = self.io.terminal.screen.selectionString(self.alloc, .{
|
const buf = self.io.terminal.screen.selectionString(self.alloc, .{
|
||||||
.sel = sel,
|
.sel = sel,
|
||||||
.trim = self.config.clipboard_trim_trailing_spaces,
|
.trim = self.config.clipboard_trim_trailing_spaces,
|
||||||
@ -1430,7 +1419,7 @@ fn setSelection(self: *Surface, sel_: ?terminal.Selection) !void {
|
|||||||
|
|
||||||
// Set the clipboard. This is not super DRY but it is clear what
|
// Set the clipboard. This is not super DRY but it is clear what
|
||||||
// we're doing for each setting without being clever.
|
// we're doing for each setting without being clever.
|
||||||
switch (self.config.copy_on_select) {
|
switch (action) {
|
||||||
.false => unreachable, // handled above with an early exit
|
.false => unreachable, // handled above with an early exit
|
||||||
|
|
||||||
// Both standard and selection clipboards are set.
|
// Both standard and selection clipboards are set.
|
||||||
@ -1469,6 +1458,22 @@ fn setSelection(self: *Surface, sel_: ?terminal.Selection) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn setSelection(self: *Surface, sel_: ?terminal.Selection) !void {
|
||||||
|
const prev_ = self.io.terminal.screen.selection;
|
||||||
|
try self.io.terminal.screen.select(sel_);
|
||||||
|
|
||||||
|
// If copy on select is false then exit early.
|
||||||
|
if (self.config.copy_on_select == .false) return;
|
||||||
|
|
||||||
|
// clear the clipboard. If the selection is set, we only set the clipboard
|
||||||
|
// again if it changed, since setting the clipboard can be an expensive
|
||||||
|
// operation.
|
||||||
|
const sel = sel_ orelse return;
|
||||||
|
if (prev_) |prev| if (sel.eql(prev)) return;
|
||||||
|
|
||||||
|
try self.copyOnMouseAction(sel, self.config.copy_on_select);
|
||||||
|
}
|
||||||
|
|
||||||
/// Change the cell size for the terminal grid. This can happen as
|
/// Change the cell size for the terminal grid. This can happen as
|
||||||
/// a result of changing the font size at runtime.
|
/// a result of changing the font size at runtime.
|
||||||
fn setCellSize(self: *Surface, size: renderer.CellSize) !void {
|
fn setCellSize(self: *Surface, size: renderer.CellSize) !void {
|
||||||
@ -3074,6 +3079,7 @@ pub fn mouseButtonCallback(
|
|||||||
// are supported by our two main apprts so we always do this. If we
|
// are supported by our two main apprts so we always do this. If we
|
||||||
// want to be careful in the future we can add a function to apprts
|
// want to be careful in the future we can add a function to apprts
|
||||||
// that let's us know.
|
// that let's us know.
|
||||||
|
|
||||||
if (button == .right and action == .press) sel: {
|
if (button == .right and action == .press) sel: {
|
||||||
self.renderer_state.mutex.lock();
|
self.renderer_state.mutex.lock();
|
||||||
defer self.renderer_state.mutex.unlock();
|
defer self.renderer_state.mutex.unlock();
|
||||||
@ -3103,14 +3109,15 @@ pub fn mouseButtonCallback(
|
|||||||
// If we already have a selection and the selection contains
|
// If we already have a selection and the selection contains
|
||||||
// where we clicked then we don't want to modify the selection.
|
// where we clicked then we don't want to modify the selection.
|
||||||
if (self.io.terminal.screen.selection) |prev_sel| {
|
if (self.io.terminal.screen.selection) |prev_sel| {
|
||||||
|
try self.copyOnMouseAction(prev_sel, self.config.copy_on_right_click);
|
||||||
if (prev_sel.contains(screen, pin)) break :sel;
|
if (prev_sel.contains(screen, pin)) break :sel;
|
||||||
|
|
||||||
// The selection doesn't contain our pin, so we create a new
|
// The selection doesn't contain our pin, so we create a new
|
||||||
// word selection where we clicked.
|
// word selection where we clicked.
|
||||||
}
|
}
|
||||||
|
|
||||||
const sel = screen.selectWord(pin) orelse break :sel;
|
const sel = screen.selectWord(pin) orelse break :sel;
|
||||||
try self.setSelection(sel);
|
try self.setSelection(sel);
|
||||||
|
try self.copyOnMouseAction(sel, self.config.copy_on_right_click);
|
||||||
try self.queueRender();
|
try self.queueRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1464,7 +1464,7 @@ fn gtkMouseDown(
|
|||||||
// If a right click isn't consumed, mouseButtonCallback selects the hovered
|
// If a right click isn't consumed, mouseButtonCallback selects the hovered
|
||||||
// word and returns false. We can use this to handle the context menu
|
// word and returns false. We can use this to handle the context menu
|
||||||
// opening under normal scenarios.
|
// opening under normal scenarios.
|
||||||
if (!consumed and button == .right) {
|
if (!consumed and button == .right and self.app.config.@"copy-on-right-click" == .false) {
|
||||||
self.showContextMenu(@floatCast(x), @floatCast(y));
|
self.showContextMenu(@floatCast(x), @floatCast(y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ pub const formatEntry = formatter.formatEntry;
|
|||||||
// Field types
|
// Field types
|
||||||
pub const ClipboardAccess = Config.ClipboardAccess;
|
pub const ClipboardAccess = Config.ClipboardAccess;
|
||||||
pub const ConfirmCloseSurface = Config.ConfirmCloseSurface;
|
pub const ConfirmCloseSurface = Config.ConfirmCloseSurface;
|
||||||
pub const CopyOnSelect = Config.CopyOnSelect;
|
pub const CopyOnMouseAction = Config.CopyOnMouseAction;
|
||||||
pub const CustomShaderAnimation = Config.CustomShaderAnimation;
|
pub const CustomShaderAnimation = Config.CustomShaderAnimation;
|
||||||
pub const FontSyntheticStyle = Config.FontSyntheticStyle;
|
pub const FontSyntheticStyle = Config.FontSyntheticStyle;
|
||||||
pub const FontStyle = Config.FontStyle;
|
pub const FontStyle = Config.FontStyle;
|
||||||
|
@ -1506,7 +1506,13 @@ keybind: Keybinds = .{},
|
|||||||
/// paste is always enabled even if this is `false`.
|
/// paste is always enabled even if this is `false`.
|
||||||
///
|
///
|
||||||
/// The default value is true on Linux and macOS.
|
/// The default value is true on Linux and macOS.
|
||||||
@"copy-on-select": CopyOnSelect = switch (builtin.os.tag) {
|
@"copy-on-select": CopyOnMouseAction = switch (builtin.os.tag) {
|
||||||
|
.linux => .true,
|
||||||
|
.macos => .true,
|
||||||
|
else => .false,
|
||||||
|
},
|
||||||
|
|
||||||
|
@"copy-on-right-click": CopyOnMouseAction = switch (builtin.os.tag) {
|
||||||
.linux => .true,
|
.linux => .true,
|
||||||
.macos => .true,
|
.macos => .true,
|
||||||
else => .false,
|
else => .false,
|
||||||
@ -5754,7 +5760,7 @@ pub const RepeatableLink = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Options for copy on select behavior.
|
/// Options for copy on select behavior.
|
||||||
pub const CopyOnSelect = enum {
|
pub const CopyOnMouseAction = enum {
|
||||||
/// Disables copy on select entirely.
|
/// Disables copy on select entirely.
|
||||||
false,
|
false,
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user