From 2137a21d2bedbb7dcdc07174358b9d98c6a452f8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 10 Mar 2025 15:22:56 +0530 Subject: [PATCH] Start work on displaying progress bar in macOS dock --- kitty/cocoa_window.m | 23 +++++++++++++++++++++++ kitty/fast_data_types.pyi | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index 8c61083eb..8b6d0b097 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -1202,6 +1202,28 @@ - (BOOL)openFileURLs:(NSPasteboard*)pasteboard Py_RETURN_NONE; } +static NSView *dock_content_view = nil; +static NSImageView *dock_image_view = nil; + +static PyObject* +cocoa_show_progress_bar_on_dock_icon(PyObject *self UNUSED, PyObject *args) { + float percent = -100; + if (!PyArg_ParseTuple(args, "|f", &percent)) return NULL; + NSDockTile *dockTile = [NSApp dockTile]; + if (!dock_content_view) { + dock_content_view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, dockTile.size.width, dockTile.size.height)]; + dock_image_view = [NSImageView.alloc initWithFrame:dock_content_view.frame]; + dock_image_view.imageScaling = NSImageScaleProportionallyDown; + dock_image_view.image = NSApp.applicationIconImage; + [dock_content_view addSubview:dock_image_view]; + } + [dock_content_view setFrameSize:dockTile.size]; + [dock_image_view setFrameSize:dockTile.size]; + [dockTile setContentView:percent < 0 ? nil : dock_content_view]; + [dockTile display]; + Py_RETURN_NONE; +} + static PyMethodDef module_methods[] = { {"cocoa_play_system_sound_by_id_async", play_system_sound_by_id_async, METH_O, ""}, {"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""}, @@ -1213,6 +1235,7 @@ - (BOOL)openFileURLs:(NSPasteboard*)pasteboard {"cocoa_set_url_handler", (PyCFunction)cocoa_set_url_handler, METH_VARARGS, ""}, {"cocoa_set_app_icon", (PyCFunction)cocoa_set_app_icon, METH_VARARGS, ""}, {"cocoa_set_dock_icon", (PyCFunction)cocoa_set_dock_icon, METH_VARARGS, ""}, + {"cocoa_show_progress_bar_on_dock_icon", (PyCFunction)cocoa_show_progress_bar_on_dock_icon, METH_VARARGS, ""}, {"cocoa_bundle_image_as_png", (PyCFunction)(void(*)(void))bundle_image_as_png, METH_VARARGS | METH_KEYWORDS, ""}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 84487e5ad..f34516bfb 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -896,6 +896,10 @@ def cocoa_set_dock_icon(icon_path: str) -> None: pass +def cocoa_show_progress_bar_on_dock_icon(progress: float = -100) -> None: + pass + + def cocoa_hide_app() -> None: pass