Merge branch 'drag_and_drop_text' of https://github.com/Luflosi/kitty

This commit is contained in:
Kovid Goyal 2019-08-24 08:39:27 +05:30
commit a0ceba407e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 27 additions and 13 deletions

View File

@ -19,6 +19,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- macOS: Add an option :opt:`macos_show_window_title_in` to control - macOS: Add an option :opt:`macos_show_window_title_in` to control
showing the window title in the menubar/titlebar (:pull:`1837`) showing the window title in the menubar/titlebar (:pull:`1837`)
- macOS: Allow drag and drop of text from other applications into kitty
(:pull:`1921`)
- When running kittens, use the colorscheme of the current window - When running kittens, use the colorscheme of the current window
rather than the configured colorscheme (:iss:`1906`) rather than the configured colorscheme (:iss:`1906`)

View File

@ -630,7 +630,7 @@ static GLFWapplicationshouldhandlereopenfun handle_reopen_callback = NULL;
markedRect = NSMakeRect(0.0, 0.0, 0.0, 0.0); markedRect = NSMakeRect(0.0, 0.0, 0.0, 0.0);
[self updateTrackingAreas]; [self updateTrackingAreas];
[self registerForDraggedTypes:@[NSPasteboardTypeFileURL]]; [self registerForDraggedTypes:@[NSPasteboardTypeFileURL, NSPasteboardTypeString]];
} }
return self; return self;
@ -1073,16 +1073,27 @@ is_ascii_control_char(char x) {
NSPasteboard* pasteboard = [sender draggingPasteboard]; NSPasteboard* pasteboard = [sender draggingPasteboard];
NSDictionary* options = @{NSPasteboardURLReadingFileURLsOnlyKey:@YES}; NSDictionary* options = @{NSPasteboardURLReadingFileURLsOnlyKey:@YES};
NSArray* urls = [pasteboard readObjectsForClasses:@[[NSURL class]] NSArray* objs = [pasteboard readObjectsForClasses:@[[NSURL class], [NSString class]]
options:options]; options:options];
if (!urls) return NO; if (!objs) return NO;
const NSUInteger count = [urls count]; const NSUInteger count = [objs count];
if (count) if (count)
{ {
char** paths = calloc(count, sizeof(char*)); char** paths = calloc(count, sizeof(char*));
for (NSUInteger i = 0; i < count; i++) for (NSUInteger i = 0; i < count; i++)
paths[i] = _glfw_strdup([urls[i] fileSystemRepresentation]); {
id obj = objs[i];
if ([obj isKindOfClass:[NSURL class]]) {
paths[i] = _glfw_strdup([obj fileSystemRepresentation]);
} else if ([obj isKindOfClass:[NSString class]]) {
paths[i] = _glfw_strdup([obj UTF8String]);
} else {
_glfwInputError(GLFW_PLATFORM_ERROR,
"Cocoa: Object is neither a URL nor a string");
paths[i] = _glfw_strdup("");
}
}
_glfwInputDrop(window, (int) count, (const char**) paths); _glfwInputDrop(window, (int) count, (const char**) paths);

View File

@ -619,12 +619,12 @@ class Boss:
if tm is not None: if tm is not None:
tm.update_tab_bar_data() tm.update_tab_bar_data()
def on_drop(self, os_window_id, paths): def on_drop(self, os_window_id, strings):
tm = self.os_window_map.get(os_window_id) tm = self.os_window_map.get(os_window_id)
if tm is not None: if tm is not None:
w = tm.active_window w = tm.active_window
if w is not None: if w is not None:
w.paste('\n'.join(paths)) w.paste('\n'.join(strings))
def on_os_window_closed(self, os_window_id, viewport_width, viewport_height): def on_os_window_closed(self, os_window_id, viewport_width, viewport_height):
self.cached_values['window-size'] = viewport_width, viewport_height self.cached_values['window-size'] = viewport_width, viewport_height

View File

@ -319,13 +319,13 @@ window_focus_callback(GLFWwindow *w, int focused) {
} }
static void static void
drop_callback(GLFWwindow *w, int count, const char **paths) { drop_callback(GLFWwindow *w, int count, const char **strings) {
if (!set_callback_window(w)) return; if (!set_callback_window(w)) return;
PyObject *p = PyTuple_New(count); PyObject *s = PyTuple_New(count);
if (p) { if (s) {
for (int i = 0; i < count; i++) PyTuple_SET_ITEM(p, i, PyUnicode_FromString(paths[i])); for (int i = 0; i < count; i++) PyTuple_SET_ITEM(s, i, PyUnicode_FromString(strings[i]));
WINDOW_CALLBACK(on_drop, "O", p); WINDOW_CALLBACK(on_drop, "O", s);
Py_CLEAR(p); Py_CLEAR(s);
request_tick_callback(); request_tick_callback();
} }
global_state.callback_os_window = NULL; global_state.callback_os_window = NULL;