This commit is contained in:
Kovid Goyal 2022-02-06 20:14:26 +05:30
commit 73b0312dcb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
8 changed files with 33 additions and 16 deletions

View File

@ -79,7 +79,10 @@ Detailed list of changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- macOS: Allow kitty to handle various URL types. Can be configured via - macOS: Allow kitty to handle various URL types. Can be configured via
:ref:`launch_actions` :ref:`launch_actions` (:pull:`4618`)
- macOS: Add a new service ``Open with kitty`` to open file types that are not
recognized by the system (:pull:`4641`)
- Fix a regression in the previous release that broke :opt:`active_tab_foreground` (:iss:`4620`) - Fix a regression in the previous release that broke :opt:`active_tab_foreground` (:iss:`4620`)

View File

@ -2256,7 +2256,7 @@ class Boss:
else: else:
w = None w = None
needs_window_replaced = False needs_window_replaced = False
if not no_replace_window: if not no_replace_window and not get_options().startup_session:
if w is not None and w.id == 1 and monotonic() - w.started_at < 2 and len(tuple(self.all_windows)) == 1: if w is not None and w.id == 1 and monotonic() - w.started_at < 2 and len(tuple(self.all_windows)) == 1:
# first window, soon after startup replace it # first window, soon after startup replace it
needs_window_replaced = True needs_window_replaced = True

View File

@ -1008,14 +1008,14 @@ typedef struct {
static CocoaPendingActionsData cocoa_pending_actions_data = {0}; static CocoaPendingActionsData cocoa_pending_actions_data = {0};
void void
set_cocoa_pending_action(CocoaPendingAction action, const char *wd) { set_cocoa_pending_action(CocoaPendingAction action, const char *data) {
if (wd) { if (data) {
if (action == LAUNCH_URL) { if (action == LAUNCH_URLS) {
ensure_space_for(&cocoa_pending_actions_data, open_urls, char*, cocoa_pending_actions_data.open_urls_count + 8, open_urls_capacity, 8, true); ensure_space_for(&cocoa_pending_actions_data, open_urls, char*, cocoa_pending_actions_data.open_urls_count + 8, open_urls_capacity, 8, true);
cocoa_pending_actions_data.open_urls[cocoa_pending_actions_data.open_urls_count++] = strdup(wd); cocoa_pending_actions_data.open_urls[cocoa_pending_actions_data.open_urls_count++] = strdup(data);
} else { } else {
if (cocoa_pending_actions_data.wd) free(cocoa_pending_actions_data.wd); if (cocoa_pending_actions_data.wd) free(cocoa_pending_actions_data.wd);
cocoa_pending_actions_data.wd = strdup(wd); cocoa_pending_actions_data.wd = strdup(data);
} }
} }
cocoa_pending_actions[action] = true; cocoa_pending_actions[action] = true;

View File

@ -527,7 +527,7 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) {
for (NSURL *url in urlArray) { for (NSURL *url in urlArray) {
NSString *path = [url path]; NSString *path = [url path];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
set_cocoa_pending_action(LAUNCH_URL, [[[NSURL fileURLWithPath:path] absoluteString] UTF8String]); set_cocoa_pending_action(LAUNCH_URLS, [[[NSURL fileURLWithPath:path] absoluteString] UTF8String]);
} }
} }
return YES; return YES;

View File

@ -456,7 +456,7 @@ static void get_window_dpi(GLFWwindow *w, double *x, double *y);
#ifdef __APPLE__ #ifdef __APPLE__
static bool static bool
apple_url_open_callback(const char* url) { apple_url_open_callback(const char* url) {
set_cocoa_pending_action(LAUNCH_URL, url); set_cocoa_pending_action(LAUNCH_URLS, url);
return true; return true;
} }

View File

@ -298,7 +298,7 @@ typedef enum {
NEXT_TAB, NEXT_TAB,
PREVIOUS_TAB, PREVIOUS_TAB,
DETACH_TAB, DETACH_TAB,
LAUNCH_URL, LAUNCH_URLS,
NEW_WINDOW, NEW_WINDOW,
CLOSE_WINDOW, CLOSE_WINDOW,
RESET_TERMINAL, RESET_TERMINAL,

View File

@ -383,15 +383,12 @@ class Tab: # {{{
import shlex import shlex
with suppress(OSError): with suppress(OSError):
with open(old_exe) as f: with open(old_exe) as f:
cmd_rest = cmd[1:]
cmd = [kitty_exe(), '+hold']
if f.read(2) == '#!': if f.read(2) == '#!':
line = f.read(4096).splitlines()[0] line = f.read(4096).splitlines()[0]
cmd += shlex.split(line) + [old_exe] cmd[:0] = shlex.split(line)
else: else:
cmd += [resolved_shell(get_options())[0], old_exe] cmd[:0] = [resolved_shell(get_options())[0]]
if cmd_rest: cmd[:0] = [kitty_exe(), '+hold']
cmd += cmd_rest
fenv: Dict[str, str] = {} fenv: Dict[str, str] = {}
if env: if env:
fenv.update(env) fenv.update(env)

View File

@ -967,6 +967,23 @@ TryExec=kitty
Exec=kitty Exec=kitty
Icon=kitty Icon=kitty
Categories=System;TerminalEmulator; Categories=System;TerminalEmulator;
'''
)
with open(os.path.join(deskdir, 'kitty-launcher.desktop'), 'w') as f:
f.write(
'''\
[Desktop Entry]
Version=1.0
Type=Application
Name=kitty URL Launcher
GenericName=Terminal emulator
Comment=Open URLs with kitty
TryExec=kitty
Exec=kitty +open %U
Icon=kitty
Categories=System;TerminalEmulator;
NoDisplay=true
MimeType=x-scheme-handler/kitty;
''' '''
) )