diff --git a/kitty/mouse.c b/kitty/mouse.c index e4b340916..c6880c846 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -122,6 +122,16 @@ encode_mouse_scroll(Window *w, bool upwards, int mods) { // }}} +static void +dispatch_mouse_event(Window *w, int button, int count, int modifiers) { + if (w->render_data.screen && PyCallable_Check(w->render_data.screen->callbacks)) { + PyObject *callback_ret = PyObject_CallMethod(w->render_data.screen->callbacks, "on_mouse_event", "{si si si}", + "button", button, "count", count, "modifiers", modifiers); + if (callback_ret == NULL) PyErr_Print(); + else Py_DECREF(callback_ret); + } +} + static inline unsigned int window_left(Window *w) { return w->geometry.left - w->padding.left; diff --git a/kitty/typing.py b/kitty/typing.py index f0f235fcc..1c8346a0a 100644 --- a/kitty/typing.py +++ b/kitty/typing.py @@ -21,3 +21,4 @@ EdgeLiteral = str PowerlineStyle = str MatchType = str Protocol = object +MouseEvent = dict diff --git a/kitty/typing.pyi b/kitty/typing.pyi index 08e4b1fba..5d88a7fdb 100644 --- a/kitty/typing.pyi +++ b/kitty/typing.pyi @@ -41,19 +41,27 @@ from .window import Window as WindowType EdgeLiteral = Literal['left', 'top', 'right', 'bottom'] MatchType = Literal['mime', 'ext', 'protocol', 'file', 'path', 'url', 'fragment_matches'] +PowerlineStyle = Literal['angled', 'slanted', 'round'] GRT_a = Literal['t', 'T', 'q', 'p', 'd', 'f', 'a'] GRT_f = Literal[24, 32, 100] GRT_t = Literal['d', 'f', 't', 's'] GRT_o = Literal['z'] GRT_m = Literal[0, 1] GRT_d = Literal['a', 'A', 'c', 'C', 'i', 'I', 'p', 'P', 'q', 'Q', 'x', 'X', 'y', 'Y', 'z', 'Z', 'f', 'F'] + + +class WindowSystemMouseEvent(TypedDict): + button: int + count: int + mods: int + + __all__ = ( 'EdgeLiteral', 'MatchType', 'GRT_a', 'GRT_f', 'GRT_t', 'GRT_o', 'GRT_m', 'GRT_d', 'GraphicsCommandType', 'HandlerType', 'AbstractEventLoop', 'AddressFamily', 'Socket', 'CompletedProcess', 'PopenType', 'Protocol', 'TypedDict', 'MarkType', 'ImageManagerType', 'Debug', 'LoopType', 'MouseEvent', 'TermManagerType', 'KittensKeyActionType', 'BossType', 'ChildType', 'BadLineType', - 'KeyActionType', 'KeyMap', 'KittyCommonOpts', 'SequenceMap', 'CoreTextFont', - 'FontConfigPattern', 'ScreenType', 'StartupCtx', 'KeyEventType', 'LayoutType', + 'KeyActionType', 'KeyMap', 'KittyCommonOpts', 'SequenceMap', 'CoreTextFont', 'WindowSystemMouseEvent', + 'FontConfigPattern', 'ScreenType', 'StartupCtx', 'KeyEventType', 'LayoutType', 'PowerlineStyle', 'RemoteCommandType', 'SessionType', 'SessionTab', 'SpecialWindowInstance', 'TabType', 'ScreenSize', 'WindowType' ) -PowerlineStyle = Literal['angled', 'slanted', 'round']