From d66074f19faf03b266175a4fa0c61edfb09ecb01 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 15 Oct 2023 21:03:41 +0530 Subject: [PATCH] Add pointer shape enum to kittens --- gen/cursors.py | 5 ++ gen/key_constants.py | 3 ++ tools/tui/loop/mouse.go | 103 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) diff --git a/gen/cursors.py b/gen/cursors.py index 89004c857..9eb39d430 100755 --- a/gen/cursors.py +++ b/gen/cursors.py @@ -134,6 +134,11 @@ def main(args: List[str]=sys.argv) -> None: patch_file('glfw/cocoa_window.m', 'glfw to cocoa', '\n'.join(f' {x}' for x in glfw_cocoa_map.values())) patch_file('docs/pointer-shapes.rst', 'list of shape css names', '\n'.join( f'#. {x}' if x else '' for x in [''] + sorted(css_names) + ['']), start_marker='.. ', end_marker='') + patch_file('tools/tui/loop/mouse.go', 'pointer shape enum', '\n'.join( + f'\t{x} PointerShape = {i}' for i, x in enumerate(enum_to_glfw_map)), start_marker='// ', end_marker='') + patch_file('tools/tui/loop/mouse.go', 'pointer shape tostring', '\n'.join( + f'''\tcase {x}: return "{x.lower().rpartition('_')[0].replace('_', '-')}"''' for x in enum_to_glfw_map), start_marker='// ', end_marker='') + subprocess.check_call(['glfw/glfw.py']) diff --git a/gen/key_constants.py b/gen/key_constants.py index d5e2e85d8..fd4d16866 100755 --- a/gen/key_constants.py +++ b/gen/key_constants.py @@ -3,6 +3,7 @@ import os import string +import subprocess import sys from pprint import pformat from typing import Any, Dict, List, Union @@ -249,6 +250,8 @@ def patch_file(path: str, what: str, text: str, start_marker: str = '/* ', end_m f.seek(0) f.truncate(0) f.write(raw) + if path.endswith('.go'): + subprocess.check_call(['go', 'fmt', path]) def serialize_dict(x: Dict[Any, Any]) -> str: diff --git a/tools/tui/loop/mouse.go b/tools/tui/loop/mouse.go index 2beb0a421..e2592f129 100644 --- a/tools/tui/loop/mouse.go +++ b/tools/tui/loop/mouse.go @@ -34,6 +34,109 @@ func (e MouseEventType) String() string { return strconv.Itoa(int(e)) } +type PointerShape uint8 + +const ( + // start pointer shape enum (auto generated by gen-key-constants.py do not edit) + DEFAULT_POINTER PointerShape = 0 + TEXT_POINTER PointerShape = 1 + POINTER_POINTER PointerShape = 2 + HELP_POINTER PointerShape = 3 + WAIT_POINTER PointerShape = 4 + PROGRESS_POINTER PointerShape = 5 + CROSSHAIR_POINTER PointerShape = 6 + VERTICAL_TEXT_POINTER PointerShape = 7 + MOVE_POINTER PointerShape = 8 + E_RESIZE_POINTER PointerShape = 9 + NE_RESIZE_POINTER PointerShape = 10 + NW_RESIZE_POINTER PointerShape = 11 + N_RESIZE_POINTER PointerShape = 12 + SE_RESIZE_POINTER PointerShape = 13 + SW_RESIZE_POINTER PointerShape = 14 + S_RESIZE_POINTER PointerShape = 15 + W_RESIZE_POINTER PointerShape = 16 + EW_RESIZE_POINTER PointerShape = 17 + NS_RESIZE_POINTER PointerShape = 18 + NESW_RESIZE_POINTER PointerShape = 19 + NWSE_RESIZE_POINTER PointerShape = 20 + ZOOM_IN_POINTER PointerShape = 21 + ZOOM_OUT_POINTER PointerShape = 22 + ALIAS_POINTER PointerShape = 23 + COPY_POINTER PointerShape = 24 + NOT_ALLOWED_POINTER PointerShape = 25 + NO_DROP_POINTER PointerShape = 26 + GRAB_POINTER PointerShape = 27 + GRABBING_POINTER PointerShape = 28 + +// end pointer shape enum +) + +func (e PointerShape) String() string { + switch e { + // start pointer shape tostring (auto generated by gen-key-constants.py do not edit) + case DEFAULT_POINTER: + return "default" + case TEXT_POINTER: + return "text" + case POINTER_POINTER: + return "pointer" + case HELP_POINTER: + return "help" + case WAIT_POINTER: + return "wait" + case PROGRESS_POINTER: + return "progress" + case CROSSHAIR_POINTER: + return "crosshair" + case VERTICAL_TEXT_POINTER: + return "vertical-text" + case MOVE_POINTER: + return "move" + case E_RESIZE_POINTER: + return "e-resize" + case NE_RESIZE_POINTER: + return "ne-resize" + case NW_RESIZE_POINTER: + return "nw-resize" + case N_RESIZE_POINTER: + return "n-resize" + case SE_RESIZE_POINTER: + return "se-resize" + case SW_RESIZE_POINTER: + return "sw-resize" + case S_RESIZE_POINTER: + return "s-resize" + case W_RESIZE_POINTER: + return "w-resize" + case EW_RESIZE_POINTER: + return "ew-resize" + case NS_RESIZE_POINTER: + return "ns-resize" + case NESW_RESIZE_POINTER: + return "nesw-resize" + case NWSE_RESIZE_POINTER: + return "nwse-resize" + case ZOOM_IN_POINTER: + return "zoom-in" + case ZOOM_OUT_POINTER: + return "zoom-out" + case ALIAS_POINTER: + return "alias" + case COPY_POINTER: + return "copy" + case NOT_ALLOWED_POINTER: + return "not-allowed" + case NO_DROP_POINTER: + return "no-drop" + case GRAB_POINTER: + return "grab" + case GRABBING_POINTER: + return "grabbing" + // end pointer shape tostring + } + return strconv.Itoa(int(e)) +} + const ( SHIFT_INDICATOR int = 1 << 2 ALT_INDICATOR = 1 << 3