From d901d8b641c88f9f22b0479d4b3326b2ed06e958 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 7 May 2025 23:54:32 +0200 Subject: Make Ctrl+C copy selection into clipboard Follows the behavior of so many other programs by copying the current text selection into the clipboard with Ctrl+C. Selecting text continues to copy it into the primary selection. Fixes: https://github.com/dillo-browser/dillo/issues/228 --- src/keys.cc | 1 + src/keys.hh | 1 + src/keysrc | 3 +++ src/ui.cc | 5 ++++- src/uicmd.cc | 10 ++++++++++ src/uicmd.hh | 1 + 6 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/keys.cc b/src/keys.cc index bbbd30bb..2a97a160 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -139,6 +139,7 @@ static const KeyBinding_t default_keys[] = { { "right" , KEYS_RIGHT , 0 , FL_Right }, { "top" , KEYS_TOP , 0 , FL_Home }, { "bottom" , KEYS_BOTTOM , 0 , FL_End }, + { "copy" , KEYS_COPY , FL_CTRL , 'c' }, { "zoom-in" , KEYS_ZOOM_IN , FL_CTRL , '+' }, { "zoom-in" , KEYS_ZOOM_IN , FL_CTRL , '=' /* US + */ }, { "zoom-out" , KEYS_ZOOM_OUT , FL_CTRL , '-' }, diff --git a/src/keys.hh b/src/keys.hh index 40c01718..72b62d18 100644 --- a/src/keys.hh +++ b/src/keys.hh @@ -49,6 +49,7 @@ typedef enum { KEYS_RIGHT, KEYS_TOP, KEYS_BOTTOM, + KEYS_COPY, KEYS_ZOOM_IN, KEYS_ZOOM_OUT, KEYS_ZOOM_RESET diff --git a/src/keysrc b/src/keysrc index bcfbb039..2d467fa2 100644 --- a/src/keysrc +++ b/src/keysrc @@ -78,6 +78,9 @@ # "goto" goes to the location bar at the top of the window. #l = goto +# "copy" copies the selected text into the clipboard. +#c = copy + # "stop" loading the page. #(stop has no default binding) diff --git a/src/ui.cc b/src/ui.cc index c5870b04..effd76cf 100644 --- a/src/ui.cc +++ b/src/ui.cc @@ -2,7 +2,7 @@ * File: ui.cc * * Copyright (C) 2005-2007 Jorge Arellano Cid - * Copyright (C) 2024 Rodrigo Arias Mallo + * Copyright (C) 2024-2025 Rodrigo Arias Mallo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -742,6 +742,9 @@ int UI::handle(int event) } else if (cmd == KEYS_FORWARD) { a_UIcmd_forw(a_UIcmd_get_bw_by_widget(this)); ret = 1; + } else if (cmd == KEYS_COPY) { + a_UIcmd_copy(a_UIcmd_get_bw_by_widget(this)); + ret = 1; } else if (cmd == KEYS_ZOOM_IN) { a_UIcmd_zoom_in(a_UIcmd_get_bw_by_widget(this)); ret = 1; diff --git a/src/uicmd.cc b/src/uicmd.cc index a2c21311..a46fd7c5 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -952,6 +952,16 @@ void a_UIcmd_redirection0(void *vbw, const DilloUrl *url) a_Nav_redirection0((BrowserWindow*)vbw, url); } +/* + * Copy selection to clipboard + */ +void a_UIcmd_copy(void *vbw) +{ + BrowserWindow *bw = (BrowserWindow*) vbw; + Layout *layout = (Layout*)bw->render_layout; + layout->copyCurrentSelection(1); +} + /* * Zoom in */ diff --git a/src/uicmd.hh b/src/uicmd.hh index 54b8750b..581eac30 100644 --- a/src/uicmd.hh +++ b/src/uicmd.hh @@ -35,6 +35,7 @@ void a_UIcmd_forw(void *vbw); void a_UIcmd_forw_nt(void *vbw); void a_UIcmd_forw_popup(void *vbw, int x, int y); void a_UIcmd_home(void *vbw); +void a_UIcmd_copy(void *vbw); void a_UIcmd_zoom_in(void *vbw); void a_UIcmd_zoom_out(void *vbw); void a_UIcmd_zoom_reset(void *vbw); -- cgit v1.2.3