-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS Finder Service to open a directory in a new kitty tab or window #1350
Conversation
Dont put the service providers code in glfw. Instead put it in kitty/cocoa_window.m You can have the interface and implementation all setup there. And you can register the services provider in cocoa_create_global_menu() which is called once by kitty during startup. |
As for licensing issues, there is no actual code there, just a header file, stub implementations and some changes to the plist, so I think we are fine. However, I am pinging @gnachman in case he objects to you learning from the iterm2 codebase and using your knowledge in kitty. |
I won't sue you for it :) |
41d16c2
to
99be6a1
Compare
@kovidgoyal like this? |
yes. |
I could open a new OS window like this: diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m
index c9cab8c5..b89a03be 100644
--- a/kitty/cocoa_window.m
+++ b/kitty/cocoa_window.m
@@ -199,6 +199,7 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) {
- (void)openWindow:(NSPasteboard*)pasteboard
userData:(NSString *)userData error:(NSError **) UNUSED error {
NSLog(@"Window ############## %@ %@", pasteboard, userData);
+ set_cocoa_pending_action(NEW_OS_WINDOW);
}
@end but how can I set the cwd of the new window? Maybe I need to create another static variable that holds the path? Judging by // If we create new OS windows during wait_events(), using global menu actions
// via the mouse causes a crash because of the way autorelease pools work in
// glfw/cocoa. So we use a flag instead.
static unsigned int cocoa_pending_actions = 0; I think, I have to use |
Yes, you will have to use another global variable. Remember to reset it |
In |
args must be a SpecialWindowInstance |
99be6a1
to
454000a
Compare
I implemented some more stuff, all that's missing now is to open the new tab/window with the correct directory in the python code. I misunderstood what |
yes it is the same thread. And you dont need to use cwd_from, simply specify cwd to SpecialWindow |
diff --git a/kitty/boss.py b/kitty/boss.py
index 6a0d609b..299ada6e 100644
--- a/kitty/boss.py
+++ b/kitty/boss.py
@@ -264,8 +264,9 @@ class Boss:
cwd_from = w.child.pid_for_cwd if w is not None else None
self._new_os_window(args, cwd_from)
- def new_os_window_with_dir(self, path):
- print(path)
+ def new_os_window_with_dir(self, cwd):
+ special_window = SpecialWindow(None, cwd=cwd)
+ self._new_os_window(special_window)
def add_child(self, window):
self.child_monitor.add_child(window.id, window.child.pid, window.child.child_fd, window.screen)
@@ -940,8 +941,9 @@ class Boss:
cwd_from = w.child.pid_for_cwd if w is not None else None
self._create_tab(args, cwd_from=cwd_from)
- def new_tab_with_dir(self, path):
- print(path)
+ def new_tab_with_dir(self, cwd):
+ special_window = SpecialWindow(None, cwd=cwd)
+ self._new_tab(special_window)
def _new_window(self, args, cwd_from=None):
tab = self.active_tab Like this? |
Yes. |
bd2d6ea
to
70a3c8d
Compare
70a3c8d
to
8177cfa
Compare
I did that, squashed all the commits, changed the commit message slightly and cleaned up the code a bit. I mainly renamed some variables and functions from |
Merged, making only one significant change to use a dict literal for |
This pull request is supposed to implement a service on macOS that allows opening a new OS or kitty window or tab from Finder. I'm pretty bad at programming in Objective-C, so keep that in mind. Any suggestions are very welcome. Right now it's only a proof of concept, it only prints a message and doesn't actually open a new tab or whatever yet. The new files are probably in the wrong folder (glfw). I'm not sure if the new header file is needed. The code from iTerm2 helped me a lot. Could this be a problem since iTerm2 is licensed under GPLv2? Or does that not matter since it's only a very small part of it, which has been modified quite a bit?