Merge branch 'drag_and_drop_text' of https://github.com/Luflosi/kitty
This commit is contained in:
commit
a0ceba407e
@ -19,6 +19,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
||||
- macOS: Add an option :opt:`macos_show_window_title_in` to control
|
||||
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
|
||||
rather than the configured colorscheme (:iss:`1906`)
|
||||
|
||||
|
||||
@ -630,7 +630,7 @@ static GLFWapplicationshouldhandlereopenfun handle_reopen_callback = NULL;
|
||||
markedRect = NSMakeRect(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
[self updateTrackingAreas];
|
||||
[self registerForDraggedTypes:@[NSPasteboardTypeFileURL]];
|
||||
[self registerForDraggedTypes:@[NSPasteboardTypeFileURL, NSPasteboardTypeString]];
|
||||
}
|
||||
|
||||
return self;
|
||||
@ -1073,16 +1073,27 @@ is_ascii_control_char(char x) {
|
||||
|
||||
NSPasteboard* pasteboard = [sender draggingPasteboard];
|
||||
NSDictionary* options = @{NSPasteboardURLReadingFileURLsOnlyKey:@YES};
|
||||
NSArray* urls = [pasteboard readObjectsForClasses:@[[NSURL class]]
|
||||
NSArray* objs = [pasteboard readObjectsForClasses:@[[NSURL class], [NSString class]]
|
||||
options:options];
|
||||
if (!urls) return NO;
|
||||
const NSUInteger count = [urls count];
|
||||
if (!objs) return NO;
|
||||
const NSUInteger count = [objs count];
|
||||
if (count)
|
||||
{
|
||||
char** paths = calloc(count, sizeof(char*));
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@ -619,12 +619,12 @@ class Boss:
|
||||
if tm is not None:
|
||||
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)
|
||||
if tm is not None:
|
||||
w = tm.active_window
|
||||
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):
|
||||
self.cached_values['window-size'] = viewport_width, viewport_height
|
||||
|
||||
12
kitty/glfw.c
12
kitty/glfw.c
@ -319,13 +319,13 @@ window_focus_callback(GLFWwindow *w, int focused) {
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
PyObject *s = PyTuple_New(count);
|
||||
if (s) {
|
||||
for (int i = 0; i < count; i++) PyTuple_SET_ITEM(s, i, PyUnicode_FromString(strings[i]));
|
||||
WINDOW_CALLBACK(on_drop, "O", s);
|
||||
Py_CLEAR(s);
|
||||
request_tick_callback();
|
||||
}
|
||||
global_state.callback_os_window = NULL;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user