Allow D&D of files into kitty

Fixes #206
This commit is contained in:
Kovid Goyal 2017-12-01 10:09:44 +05:30
parent 868c1d634b
commit 08ee77d11c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 24 additions and 0 deletions

View File

@ -34,6 +34,9 @@ version 0.6.0 [future]
- Add more options to customize the tab-bar's appearance (font styles and
separator)
- Allow drag and drop of files into kitty. On drop kitty will paste the
file path to the running program.
version 0.5.1 [2017-12-01]
---------------------------

View File

@ -255,6 +255,13 @@ class Boss:
if w is not None:
w.focus_changed(focused)
def on_drop(self, os_window_id, paths):
tm = self.os_window_map.get(os_window_id)
if tm is not None:
w = tm.active_window
if w is not None:
w.paste('\n'.join(paths))
def on_os_window_closed(self, os_window_id, viewport_width, viewport_height):
cached_values['window-size'] = viewport_width, viewport_height
tm = self.os_window_map.pop(os_window_id, None)

View File

@ -154,6 +154,19 @@ window_focus_callback(GLFWwindow *w, int focused) {
}
global_state.callback_os_window = NULL;
}
static void
drop_callback(GLFWwindow *w, int count, const char **paths) {
if (!set_callback_window(w)) return;
PyObject *p = PyTuple_New(count);
if (p) {
for (int i = 0; i < count; i++) PyTuple_SET_ITEM(p, i, PyUnicode_FromString(paths[i]));
WINDOW_CALLBACK(on_drop, "O", p);
Py_CLEAR(p);
}
global_state.callback_os_window = NULL;
}
// }}}
void
@ -266,6 +279,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
glfwSetCursorPosCallback(glfw_window, cursor_pos_callback);
glfwSetKeyCallback(glfw_window, key_callback);
glfwSetWindowFocusCallback(glfw_window, window_focus_callback);
glfwSetDropCallback(glfw_window, drop_callback);
#ifdef __APPLE__
if (OPT(macos_hide_titlebar)) {
if (glfwGetCocoaWindow) { if (!cocoa_make_window_resizable(glfwGetCocoaWindow(glfw_window))) { PyErr_Print(); } }