diff --git a/kitty/glfw.c b/kitty/glfw.c index fdad95229..7e14b515b 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -266,6 +266,15 @@ set_click_cursor(Window *self, PyObject *args) { Py_RETURN_NONE; } +static PyObject* +set_clipboard_string(Window *self, PyObject *args) { + char *title; + if(!PyArg_ParseTuple(args, "s", &title)) return NULL; + glfwSetClipboardString(self->window, title); + Py_RETURN_NONE; +} + + static PyObject* _set_title(Window *self, PyObject *args) { char *title; @@ -286,6 +295,7 @@ static PyMethodDef methods[] = { MND(set_input_mode, METH_VARARGS), MND(is_key_pressed, METH_VARARGS), MND(set_click_cursor, METH_VARARGS), + MND(set_clipboard_string, METH_VARARGS), MND(make_context_current, METH_NOARGS), {"set_title", (PyCFunction)_set_title, METH_VARARGS, ""}, {NULL} /* Sentinel */ diff --git a/kitty/window.py b/kitty/window.py index f8b4411c4..68b4fd52e 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -208,6 +208,12 @@ class Window: text = text.decode('utf-8') self.paste(text) + def copy_to_clipboard(self): + text = self.char_grid.text_for_selection() + if text: + tm = tab_manager() + tm.queue_ui_action(tm.glfw_window.set_clipboard_string, text) + def scroll_line_up(self): self.char_grid.scroll('line', True) glfw_post_empty_event()