macOS: add menu items for new_window and close_window

This commit is contained in:
Luflosi 2021-05-23 20:28:50 +02:00
parent f178dff4e0
commit 4a67af9b90
No known key found for this signature in database
GPG Key ID: 4E41E29EDCC345D0
4 changed files with 13 additions and 3 deletions

View File

@ -997,6 +997,8 @@ process_global_state(void *data) {
if (cocoa_pending_actions & NEXT_TAB) { call_boss(next_tab, NULL); }
if (cocoa_pending_actions & PREVIOUS_TAB) { call_boss(previous_tab, NULL); }
if (cocoa_pending_actions & DETACH_TAB) { call_boss(detach_tab, NULL); }
if (cocoa_pending_actions & NEW_WINDOW) { call_boss(new_window, NULL); }
if (cocoa_pending_actions & CLOSE_WINDOW) { call_boss(close_window, NULL); }
if (cocoa_pending_actions_data.wd) {
if (cocoa_pending_actions & NEW_OS_WINDOW_WITH_WD) { call_boss(new_os_window_with_wd, "s", cocoa_pending_actions_data.wd); }
if (cocoa_pending_actions & NEW_TAB_WITH_WD) { call_boss(new_tab_with_wd, "s", cocoa_pending_actions_data.wd); }

View File

@ -88,6 +88,8 @@ PENDING(close_tab, CLOSE_TAB)
PENDING(new_tab, NEW_TAB)
PENDING(next_tab, NEXT_TAB)
PENDING(previous_tab, PREVIOUS_TAB)
PENDING(new_window, NEW_WINDOW)
PENDING(close_window, CLOSE_WINDOW)
- (void)open_kitty_website_url:(id)sender {
(void)sender;
@ -115,7 +117,7 @@ typedef struct {
} GlobalShortcut;
typedef struct {
GlobalShortcut new_os_window, close_os_window, close_tab, edit_config_file;
GlobalShortcut previous_tab, next_tab, new_tab;
GlobalShortcut previous_tab, next_tab, new_tab, new_window, close_window;
} GlobalShortcuts;
static GlobalShortcuts global_shortcuts;
@ -129,6 +131,7 @@ cocoa_set_global_shortcut(PyObject *self UNUSED, PyObject *args) {
#define Q(x) if (strcmp(name, #x) == 0) gs = &global_shortcuts.x
Q(new_os_window); else Q(close_os_window); else Q(close_tab); else Q(edit_config_file);
else Q(new_tab); else Q(next_tab); else Q(previous_tab);
else Q(new_window); else Q(close_window);
#undef Q
if (gs == NULL) { PyErr_SetString(PyExc_KeyError, "Unknown shortcut name"); return NULL; }
int cocoa_mods;
@ -415,9 +418,11 @@ cocoa_create_global_menu(void) {
[shellMenuItem setSubmenu:shellMenu];
MENU_ITEM(shellMenu, @"New OS Window", new_os_window);
MENU_ITEM(shellMenu, @"New Tab", new_tab);
MENU_ITEM(shellMenu, @"New Window", new_window);
[shellMenu addItem:[NSMenuItem separatorItem]];
MENU_ITEM(shellMenu, @"Close OS Window", close_os_window);
MENU_ITEM(shellMenu, @"Close Tab", close_tab);
MENU_ITEM(shellMenu, @"Close Window", close_window);
[shellMenu release];
NSMenuItem* windowMenuItem =

View File

@ -135,7 +135,8 @@ def set_x11_window_icon() -> None:
def _run_app(opts: OptionsStub, args: CLIOptions, bad_lines: Sequence[BadLine] = ()) -> None:
global_shortcuts: Dict[str, SingleKey] = {}
if is_macos:
for ac in ('new_os_window', 'close_os_window', 'close_tab', 'edit_config_file', 'previous_tab', 'next_tab', 'new_tab'):
for ac in ('new_os_window', 'close_os_window', 'close_tab', 'edit_config_file', 'previous_tab',
'next_tab', 'new_tab', 'new_window', 'close_window'):
val = get_macos_shortcut_for(opts, ac)
if val is not None:
global_shortcuts[ac] = val

View File

@ -271,7 +271,9 @@ typedef enum {
NEXT_TAB = 128,
PREVIOUS_TAB = 256,
DETACH_TAB = 512,
OPEN_FILE = 1024
OPEN_FILE = 1024,
NEW_WINDOW = 2048,
CLOSE_WINDOW = 4096,
} CocoaPendingAction;
void set_cocoa_pending_action(CocoaPendingAction action, const char*);
#endif