diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57c6d72..903d189 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,48 @@ on: # yamllint disable-line rule:truthy - cron: "0 7 * * *" jobs: - build: + test-addon-blender-before-v41: + name: Test add-on + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + blender_version: + [ + "2.80", "2.81", "2.82", "2.83", + "2.90", "2.91", "2.92", "2.93", + "3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", + "4.0", "4.1", + ] + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.7" + + - name: Get required packages for Blender + run: | + sudo apt-get update -qq + sudo apt-get install -y blender wget python3 python3-pip zip + + - name: Get required pip packages + run: pip3 install -r requirements.txt + + - name: Download Blender + run: bash tools/download_blender.sh ${{ matrix.blender_version }} blender-bin + + - name: Copy add-on to Blender add-on's directory + run: cp -r src/screencast_keys blender-bin/blender-v${{ matrix.blender_version }}-bin/${{ matrix.blender_version }}/scripts/addons + + - name: Run add-on unittest + run: blender-bin/blender-v${{ matrix.blender_version }}-bin/blender --factory-startup --background -noaudio --python tests/python/run_tests.py + env: + SK_CONSOLE_MODE: true + + test-addon-blender-after-v42: name: Test add-on runs-on: ubuntu-latest strategy: diff --git a/src/screencast_keys/__init__.py b/src/screencast_keys/__init__.py index 9fdad3c..a572f10 100644 --- a/src/screencast_keys/__init__.py +++ b/src/screencast_keys/__init__.py @@ -41,6 +41,7 @@ # pylint: disable=E0601 importlib.reload(gpu_utils) importlib.reload(utils) + importlib.reload(c_structure) # extensions.blender.org: Delete line utils.bl_class_registry.BlClassRegistry.cleanup() importlib.reload(preferences) importlib.reload(ops) @@ -50,6 +51,7 @@ import bpy from . import gpu_utils from . import utils + from . import c_structure # extensions.blender.org: Delete line from . import preferences from . import ops from . import ui diff --git a/src/screencast_keys/c_structure/__init__.py b/src/screencast_keys/c_structure/__init__.py new file mode 100644 index 0000000..ddb53f6 --- /dev/null +++ b/src/screencast_keys/c_structure/__init__.py @@ -0,0 +1,108 @@ +# + +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + + +NOT_SUPPORTED = False + +if "bpy" in locals(): + import importlib + # pylint: disable=E0601 + # pylint: disable=E0602 + if compat.check_version(2, 79, 0) == 0: + importlib.reload(v279) + elif compat.check_version(2, 80, 0) == 0: + importlib.reload(v280) + elif compat.check_version(2, 81, 0) == 0: + importlib.reload(v281) + elif compat.check_version(2, 82, 0) == 0: + importlib.reload(v282) + elif compat.check_version(2, 83, 0) == 0: + importlib.reload(v283) + elif compat.check_version(2, 90, 0) == 0: + importlib.reload(v290) + elif compat.check_version(2, 91, 0) == 0: + importlib.reload(v291) + elif compat.check_version(2, 92, 0) == 0: + importlib.reload(v292) + elif compat.check_version(2, 93, 0) == 0: + importlib.reload(v293) + elif compat.check_version(3, 0, 0) == 0: + importlib.reload(v30) + elif compat.check_version(3, 1, 0) == 0: + importlib.reload(v31) + elif compat.check_version(3, 2, 0) == 0: + importlib.reload(v32) + elif compat.check_version(3, 3, 0) == 0: + importlib.reload(v33) + elif compat.check_version(3, 4, 0) == 0: + importlib.reload(v34) + elif compat.check_version(3, 5, 0) == 0: + importlib.reload(v35) + elif compat.check_version(3, 6, 0) == 0: + importlib.reload(v36) + elif compat.check_version(4, 0, 0) == 0: + importlib.reload(v40) + elif compat.check_version(4, 1, 0) == 0: + importlib.reload(v41) + else: + importlib.reload(v41) + NOT_SUPPORTED = True +else: + import bpy + from ..utils import compatibility as compat + if compat.check_version(2, 79, 0) == 0: + from .v279 import * + elif compat.check_version(2, 80, 0) == 0: + from .v280 import * + elif compat.check_version(2, 81, 0) == 0: + from .v281 import * + elif compat.check_version(2, 82, 0) == 0: + from .v282 import * + elif compat.check_version(2, 83, 0) == 0: + from .v283 import * + elif compat.check_version(2, 90, 0) == 0: + from .v290 import * + elif compat.check_version(2, 91, 0) == 0: + from .v291 import * + elif compat.check_version(2, 92, 0) == 0: + from .v292 import * + elif compat.check_version(2, 93, 0) == 0: + from .v293 import * + elif compat.check_version(3, 0, 0) == 0: + from .v30 import * + elif compat.check_version(3, 1, 0) == 0: + from .v31 import * + elif compat.check_version(3, 2, 0) == 0: + from .v32 import * + elif compat.check_version(3, 3, 0) == 0: + from .v33 import * + elif compat.check_version(3, 4, 0) == 0: + from .v34 import * + elif compat.check_version(3, 5, 0) == 0: + from .v35 import * + elif compat.check_version(3, 6, 0) == 0: + from .v36 import * + elif compat.check_version(4, 0, 0) == 0: + from .v40 import * + elif compat.check_version(4, 1, 0) == 0: + from .v41 import * + else: + from .v41 import * + NOT_SUPPORTED = True diff --git a/src/screencast_keys/c_structure/v279.py b/src/screencast_keys/c_structure/v279.py new file mode 100644 index 0000000..5192ccb --- /dev/null +++ b/src/screencast_keys/c_structure/v279.py @@ -0,0 +1,202 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + + ("screen", c_void_p), # struct bScreen + ("newscreen", c_void_p), # struct bScreen + ("screenname", c_char * 64), + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_short), + ("monitor", c_short), + ("active", c_short), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_short), + ("multisamples", c_short), + ("pad", c_short * 3), + + ("winid", c_int), + + ("lock_pie_event", c_short), + ("last_pie_event", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("curswin", c_void_p), # struct wmSubWindow + + ("tweak", c_void_p), # struct wmGesture + + ("ime_data", c_void_p), # struct wmIMEData + + ("drawmethod", c_int), + ("drawfail", c_int), + ("drawdata", ListBase), + + ("queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("subwindows", ListBase), + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_short * 3), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("keymap", c_void_p), # struct wmKeyMap + ("bblocal", c_void_p), # struct rcti + ("bbwin", c_void_p), # struct rcti + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v280.py b/src/screencast_keys/c_structure/v280.py new file mode 100644 index 0000000..ed4ee1b --- /dev/null +++ b/src/screencast_keys/c_structure/v280.py @@ -0,0 +1,222 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_short), + ("monitor", c_short), + ("active", c_short), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_short), + + ("winid", c_int), + + ("lock_pie_event", c_short), + ("last_pie_event", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v281.py b/src/screencast_keys/c_structure/v281.py new file mode 100644 index 0000000..ed4ee1b --- /dev/null +++ b/src/screencast_keys/c_structure/v281.py @@ -0,0 +1,222 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_short), + ("monitor", c_short), + ("active", c_short), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_short), + + ("winid", c_int), + + ("lock_pie_event", c_short), + ("last_pie_event", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v282.py b/src/screencast_keys/c_structure/v282.py new file mode 100644 index 0000000..ed4ee1b --- /dev/null +++ b/src/screencast_keys/c_structure/v282.py @@ -0,0 +1,222 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_short), + ("monitor", c_short), + ("active", c_short), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_short), + + ("winid", c_int), + + ("lock_pie_event", c_short), + ("last_pie_event", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v283.py b/src/screencast_keys/c_structure/v283.py new file mode 100644 index 0000000..1b453b6 --- /dev/null +++ b/src/screencast_keys/c_structure/v283.py @@ -0,0 +1,223 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("_pad0", c_char * 4), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + + ("winid", c_int), + + ("lock_pie_event", c_short), + ("last_pie_event", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v290.py b/src/screencast_keys/c_structure/v290.py new file mode 100644 index 0000000..1b453b6 --- /dev/null +++ b/src/screencast_keys/c_structure/v290.py @@ -0,0 +1,223 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("_pad0", c_char * 4), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + + ("winid", c_int), + + ("lock_pie_event", c_short), + ("last_pie_event", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v291.py b/src/screencast_keys/c_structure/v291.py new file mode 100644 index 0000000..1b453b6 --- /dev/null +++ b/src/screencast_keys/c_structure/v291.py @@ -0,0 +1,223 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("_pad0", c_char * 4), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + + ("winid", c_int), + + ("lock_pie_event", c_short), + ("last_pie_event", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v292.py b/src/screencast_keys/c_structure/v292.py new file mode 100644 index 0000000..1b453b6 --- /dev/null +++ b/src/screencast_keys/c_structure/v292.py @@ -0,0 +1,223 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("_pad0", c_char * 4), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + + ("winid", c_int), + + ("lock_pie_event", c_short), + ("last_pie_event", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v293.py b/src/screencast_keys/c_structure/v293.py new file mode 100644 index 0000000..ccb5f9c --- /dev/null +++ b/src/screencast_keys/c_structure/v293.py @@ -0,0 +1,229 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("winid", c_int), + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + + ("event_queue_check_drag_handled", c_char), + + ("_pad0", c_char * 1), + + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v30.py b/src/screencast_keys/c_structure/v30.py new file mode 100644 index 0000000..ccb5f9c --- /dev/null +++ b/src/screencast_keys/c_structure/v30.py @@ -0,0 +1,229 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("winid", c_int), + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + + ("event_queue_check_drag_handled", c_char), + + ("_pad0", c_char * 1), + + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v31.py b/src/screencast_keys/c_structure/v31.py new file mode 100644 index 0000000..ccb5f9c --- /dev/null +++ b/src/screencast_keys/c_structure/v31.py @@ -0,0 +1,229 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("winid", c_int), + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + + ("event_queue_check_drag_handled", c_char), + + ("_pad0", c_char * 1), + + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + + ("eventstate", c_void_p), # struct wmEvent + + ("tweak", c_void_p), # struct wmGesture + ("ime_data", c_void_p), # struct wmIMEData + + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v32.py b/src/screencast_keys/c_structure/v32.py new file mode 100644 index 0000000..95f5b9d --- /dev/null +++ b/src/screencast_keys/c_structure/v32.py @@ -0,0 +1,229 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("winid", c_int), + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + + ("event_queue_check_drag_handled", c_char), + + ("_pad0", c_char * 1), + + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + + ("eventstate", c_void_p), # struct wmEvent + ("event_last_handled", c_void_p), # struct wmEvent + + ("ime_data", c_void_p), # struct wmIMEData + + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v33.py b/src/screencast_keys/c_structure/v33.py new file mode 100644 index 0000000..8b9093b --- /dev/null +++ b/src/screencast_keys/c_structure/v33.py @@ -0,0 +1,230 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + + +class Link(Structure): + """Defined in source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), # struct Link + ("prev", POINTER(Link)), # struct Link +] + + +class ListBase(Structure): + # pylint: disable=W0201 + """Defined in source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +class ScrAreaMap(Structure): + """Defined in source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=C0103 +class wmWindow(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + + ("parent", POINTER(wmWindow)), + + ("scene", c_void_p), # struct Scene + ("new_scene", c_void_p), # struct Scene + ("view_layer_name", c_char * 64), + ("unpinned_scene", c_void_p), # struct Scene + + ("workspace_hook", c_void_p), # struct WorkSpaceInstanceHook + + ("global_areas", ScrAreaMap), + + ("screen", c_void_p), # struct bScreen + + ("winid", c_int), + + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + + ("event_queue_check_drag_handled", c_char), + + ("_pad0", c_char * 1), + + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + + ("eventstate", c_void_p), # struct wmEvent + ("event_last_handled", c_void_p), # struct wmEvent + + ("ime_data", c_void_p), # struct wmIMEData + + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + + ("gesture", ListBase), + + ("stereo3d_format", c_void_p), # struct Stereo3dFormat + + ("drawcalls", ListBase), + + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=C0103 +class wmOperator(Structure): + """Defined in source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + + ("idname", c_char * 64), + ("properties", c_void_p), # IDProperty + + ("type", c_void_p), # struct wmOperatorType + ("customdata", c_void_p), + ("py_instance", c_void_p), + + ("ptr", c_void_p), # struct PointerRNA + ("reports", c_void_p), # struct ReportList + + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + ("layout", c_void_p), # struct uiLayout + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=C0103 +class wmEventHandler(Structure): + """Defined in source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + # from struct wmEventHandler + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + + ("type", c_int8), # enum eWM_EventHandlerType + ("flag", c_char), + + ("poll", c_void_p), # (*EventHandlerPoll) + + + # from struct wmEventHandler_Op + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v34.py b/src/screencast_keys/c_structure/v34.py new file mode 100644 index 0000000..e8303bf --- /dev/null +++ b/src/screencast_keys/c_structure/v34.py @@ -0,0 +1,224 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + """Defined in $source/blender/windowmanager/wm_event_system.h""" + + WM_HANDLER_TYPE_GIZMO = 1 + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + WM_HANDLER_TYPE_DROPBOX = 4 + WM_HANDLER_TYPE_KEYMAP = 5 + + +# pylint: disable=W0201 +class Link(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), + ("prev", POINTER(Link)), +] + + +# pylint: disable=W0201 +class ListBase(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +# pylint: disable=W0201 +class ScrAreaMap(Structure): + """Defined in $source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=W0201 +class wmWindow(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + ("parent", POINTER(wmWindow)), + # Scene + ("scene", c_void_p), + # Scene + ("new_scene", c_void_p), + ("view_layer_name", c_char * 64), + # Scene + ("unpinned_scene", c_void_p), + # WorkSpaceInstanceHook + ("workspace_hook", c_void_p), + ("global_areas", ScrAreaMap), + # bScreen + ("screen", c_void_p), + ("winid", c_int), + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + ("event_queue_check_drag_handled", c_char), + ("_pad0", c_char * 1), + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + # wmEvent + ("eventstate", c_void_p), + # wmEvent + ("event_last_handled", c_void_p), + # wmIMEData + ("ime_data", c_void_p), + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + ("gesture", ListBase), + # Stereo3dFormat + ("stereo3d_format", c_void_p), + ("drawcalls", ListBase), + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=W0201 +class wmOperator(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + ("idname", c_char * 64), + # IDProperty + ("properties", c_void_p), + # wmOperatorType + ("type", c_void_p), + ("customdata", c_void_p), + ("py_instance", c_void_p), + # PointerRNA + ("ptr", c_void_p), + # ReportList + ("reports", c_void_p), + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + # uiLayout + ("layout", c_void_p), + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=W0201 +class wmEventHandler(Structure): + """Defined in $source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + # eWM_EventHandlerType + ("type", c_int8), + ("flag", c_char), + # EventHandlerPoll + ("poll", c_void_p), + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v35.py b/src/screencast_keys/c_structure/v35.py new file mode 100644 index 0000000..03f2a88 --- /dev/null +++ b/src/screencast_keys/c_structure/v35.py @@ -0,0 +1,228 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + """Defined in $source/blender/windowmanager/wm_event_system.h""" + + WM_HANDLER_TYPE_GIZMO = 1 + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + WM_HANDLER_TYPE_DROPBOX = 4 + WM_HANDLER_TYPE_KEYMAP = 5 + + +# pylint: disable=W0201 +class Link(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), + ("prev", POINTER(Link)), +] + + +# pylint: disable=W0201 +class ListBase(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +# pylint: disable=W0201 +class ScrAreaMap(Structure): + """Defined in $source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=W0201 +class wmWindow(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + ("parent", POINTER(wmWindow)), + # Scene + ("scene", c_void_p), + # Scene + ("new_scene", c_void_p), + ("view_layer_name", c_char * 64), + # Scene + ("unpinned_scene", c_void_p), + # WorkSpaceInstanceHook + ("workspace_hook", c_void_p), + ("global_areas", ScrAreaMap), + # bScreen + ("screen", c_void_p), + ("winid", c_int), + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + ("event_queue_check_drag_handled", c_char), + ("event_queue_consecutive_gesture_type", c_char), + ("event_queue_consecutive_gesture_xy", c_int * 2), + # wmEvent_ConsecutiveData + ("event_queue_consecutive_gesture_data", c_void_p), + # wmEvent + ("eventstate", c_void_p), + # wmEvent + ("event_last_handled", c_void_p), + # wmIMEData + ("ime_data", c_void_p), + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + ("gesture", ListBase), + # Stereo3dFormat + ("stereo3d_format", c_void_p), + ("drawcalls", ListBase), + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=W0201 +class wmOperator(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + ("idname", c_char * 64), + # IDProperty + ("properties", c_void_p), + # wmOperatorType + ("type", c_void_p), + ("customdata", c_void_p), + ("py_instance", c_void_p), + # PointerRNA + ("ptr", c_void_p), + # ReportList + ("reports", c_void_p), + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + # uiLayout + ("layout", c_void_p), + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=W0201 +class wmEventHandler(Structure): + """Defined in $source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + # eWM_EventHandlerType + ("type", c_int8), + # eWM_EventHandlerFlag + ("flag", c_int8), + # EventHandlerPoll + ("poll", c_void_p), + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v36.py b/src/screencast_keys/c_structure/v36.py new file mode 100644 index 0000000..03f2a88 --- /dev/null +++ b/src/screencast_keys/c_structure/v36.py @@ -0,0 +1,228 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + """Defined in $source/blender/windowmanager/wm_event_system.h""" + + WM_HANDLER_TYPE_GIZMO = 1 + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + WM_HANDLER_TYPE_DROPBOX = 4 + WM_HANDLER_TYPE_KEYMAP = 5 + + +# pylint: disable=W0201 +class Link(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), + ("prev", POINTER(Link)), +] + + +# pylint: disable=W0201 +class ListBase(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +# pylint: disable=W0201 +class ScrAreaMap(Structure): + """Defined in $source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=W0201 +class wmWindow(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + ("parent", POINTER(wmWindow)), + # Scene + ("scene", c_void_p), + # Scene + ("new_scene", c_void_p), + ("view_layer_name", c_char * 64), + # Scene + ("unpinned_scene", c_void_p), + # WorkSpaceInstanceHook + ("workspace_hook", c_void_p), + ("global_areas", ScrAreaMap), + # bScreen + ("screen", c_void_p), + ("winid", c_int), + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + ("event_queue_check_drag_handled", c_char), + ("event_queue_consecutive_gesture_type", c_char), + ("event_queue_consecutive_gesture_xy", c_int * 2), + # wmEvent_ConsecutiveData + ("event_queue_consecutive_gesture_data", c_void_p), + # wmEvent + ("eventstate", c_void_p), + # wmEvent + ("event_last_handled", c_void_p), + # wmIMEData + ("ime_data", c_void_p), + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + ("gesture", ListBase), + # Stereo3dFormat + ("stereo3d_format", c_void_p), + ("drawcalls", ListBase), + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=W0201 +class wmOperator(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + ("idname", c_char * 64), + # IDProperty + ("properties", c_void_p), + # wmOperatorType + ("type", c_void_p), + ("customdata", c_void_p), + ("py_instance", c_void_p), + # PointerRNA + ("ptr", c_void_p), + # ReportList + ("reports", c_void_p), + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + # uiLayout + ("layout", c_void_p), + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=W0201 +class wmEventHandler(Structure): + """Defined in $source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + # eWM_EventHandlerType + ("type", c_int8), + # eWM_EventHandlerFlag + ("flag", c_int8), + # EventHandlerPoll + ("poll", c_void_p), + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v40.py b/src/screencast_keys/c_structure/v40.py new file mode 100644 index 0000000..03f2a88 --- /dev/null +++ b/src/screencast_keys/c_structure/v40.py @@ -0,0 +1,228 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + """Defined in $source/blender/windowmanager/wm_event_system.h""" + + WM_HANDLER_TYPE_GIZMO = 1 + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + WM_HANDLER_TYPE_DROPBOX = 4 + WM_HANDLER_TYPE_KEYMAP = 5 + + +# pylint: disable=W0201 +class Link(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), + ("prev", POINTER(Link)), +] + + +# pylint: disable=W0201 +class ListBase(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +# pylint: disable=W0201 +class ScrAreaMap(Structure): + """Defined in $source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=W0201 +class wmWindow(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + ("parent", POINTER(wmWindow)), + # Scene + ("scene", c_void_p), + # Scene + ("new_scene", c_void_p), + ("view_layer_name", c_char * 64), + # Scene + ("unpinned_scene", c_void_p), + # WorkSpaceInstanceHook + ("workspace_hook", c_void_p), + ("global_areas", ScrAreaMap), + # bScreen + ("screen", c_void_p), + ("winid", c_int), + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + ("event_queue_check_drag_handled", c_char), + ("event_queue_consecutive_gesture_type", c_char), + ("event_queue_consecutive_gesture_xy", c_int * 2), + # wmEvent_ConsecutiveData + ("event_queue_consecutive_gesture_data", c_void_p), + # wmEvent + ("eventstate", c_void_p), + # wmEvent + ("event_last_handled", c_void_p), + # wmIMEData + ("ime_data", c_void_p), + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + ("gesture", ListBase), + # Stereo3dFormat + ("stereo3d_format", c_void_p), + ("drawcalls", ListBase), + ("cursor_keymap_status", c_void_p), +] + + +# pylint: disable=W0201 +class wmOperator(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + ("idname", c_char * 64), + # IDProperty + ("properties", c_void_p), + # wmOperatorType + ("type", c_void_p), + ("customdata", c_void_p), + ("py_instance", c_void_p), + # PointerRNA + ("ptr", c_void_p), + # ReportList + ("reports", c_void_p), + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + # uiLayout + ("layout", c_void_p), + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=W0201 +class wmEventHandler(Structure): + """Defined in $source/blender/windowmanager/wm_event_system.h""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + # eWM_EventHandlerType + ("type", c_int8), + # eWM_EventHandlerFlag + ("flag", c_int8), + # EventHandlerPoll + ("poll", c_void_p), + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/c_structure/v41.py b/src/screencast_keys/c_structure/v41.py new file mode 100644 index 0000000..12c8131 --- /dev/null +++ b/src/screencast_keys/c_structure/v41.py @@ -0,0 +1,231 @@ +from ctypes import ( + c_void_p, c_char, c_short, c_int, c_int8, c_uint64, + addressof, cast, pointer, + Structure, + POINTER, +) + + +# pylint: disable=C0103 +class eWM_EventHandlerType: + """Defined in $source/blender/windowmanager/wm_event_system.hh""" + + WM_HANDLER_TYPE_GIZMO = 1 + WM_HANDLER_TYPE_UI = 2 + WM_HANDLER_TYPE_OP = 3 + WM_HANDLER_TYPE_DROPBOX = 4 + WM_HANDLER_TYPE_KEYMAP = 5 + + +# pylint: disable=W0201 +class Link(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + +# pylint: disable=W0212 +Link._fields_ = [ + ("next", POINTER(Link)), + ("prev", POINTER(Link)), +] + + +# pylint: disable=W0201 +class ListBase(Structure): + """Defined in $source/blender/makesdna/DNA_listBase.h""" + + def remove(self, vlink): + """Ref: BLI_remlink""" + + link = vlink + if not vlink: + return + + if link.next: + link.next.contents.prev = link.prev + if link.prev: + link.prev.contents.next = link.next + + if self.last == addressof(link): + self.last = cast(link.prev, c_void_p) + if self.first == addressof(link): + self.first = cast(link.next, c_void_p) + + def find(self, number): + """Ref: BLI_findlink""" + + link = None + if number >= 0: + link = cast(c_void_p(self.first), POINTER(Link)) + while link and number != 0: + number -= 1 + link = link.contents.next + return link.contents if link else None + + def insert_after(self, vprevlink, vnewlink): + """Ref: BLI_insertlinkafter""" + + prevlink = vprevlink + newlink = vnewlink + + if not newlink: + return + + def gen_ptr(link): + if isinstance(link, (int, type(None))): + return cast(c_void_p(link), POINTER(Link)) + else: + return pointer(link) + + if not self.first: + self.first = self.last = addressof(newlink) + return + + if not prevlink: + newlink.prev = None + newlink.next = gen_ptr(self.first) + newlink.next.contents.prev = gen_ptr(newlink) + self.first = addressof(newlink) + return + + if self.last == addressof(prevlink): + self.last = addressof(newlink) + + newlink.next = prevlink.next + newlink.prev = gen_ptr(prevlink) + prevlink.next = gen_ptr(newlink) + if newlink.next: + newlink.next.prev = gen_ptr(newlink) + + +# pylint: disable=W0212 +ListBase._fields_ = [ + ("first", c_void_p), + ("last", c_void_p), +] + + +# pylint: disable=W0201 +class ScrAreaMap(Structure): + """Defined in $source/blender/makesdna/DNA_screen_types.h""" + + +# pylint: disable=W0212 +ScrAreaMap._fields_ = [ + ("vertbase", ListBase), + ("edgebase", ListBase), + ("areabase", ListBase), +] + + +# pylint: disable=W0201 +class wmWindow(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmWindow._fields_ = [ + ("next", POINTER(wmWindow)), + ("prev", POINTER(wmWindow)), + ("ghostwin", c_void_p), + ("gpuctx", c_void_p), + ("parent", POINTER(wmWindow)), + # Scene + ("scene", c_void_p), + # Scene + ("new_scene", c_void_p), + ("view_layer_name", c_char * 64), + # Scene + ("unpinned_scene", c_void_p), + # WorkSpaceInstanceHook + ("workspace_hook", c_void_p), + ("global_areas", ScrAreaMap), + # bScreen + ("screen", c_void_p), + ("winid", c_int), + ("posx", c_short), + ("posy", c_short), + ("sizex", c_short), + ("sizey", c_short), + ("windowstate", c_char), + ("active", c_char), + ("cursor", c_short), + ("lastcursor", c_short), + ("modalcursor", c_short), + ("grabcursor", c_short), + ("pie_event_type_lock", c_short), + ("pie_event_type_last", c_short), + ("addmousemove", c_char), + ("tag_cursor_refresh", c_char), + ("event_queue_check_click", c_char), + ("event_queue_check_drag", c_char), + ("event_queue_check_drag_handled", c_char), + ("event_queue_consecutive_gesture_type", c_char), + ("event_queue_consecutive_gesture_xy", c_int * 2), + # wmEvent_ConsecutiveData + ("event_queue_consecutive_gesture_data", c_void_p), + # wmEvent + ("eventstate", c_void_p), + # wmEvent + ("event_last_handled", c_void_p), + # wmIMEData + ("ime_data", c_void_p), + ("ime_data_is_composing", c_char), + ("_pad1", c_char * 7), + ("event_queue", ListBase), + ("handlers", ListBase), + ("modalhandlers", ListBase), + ("gesture", ListBase), + # Stereo3dFormat + ("stereo3d_format", c_void_p), + ("drawcalls", ListBase), + ("cursor_keymap_status", c_void_p), + ("eventstate_prev_press_time_ms", c_uint64), +] + + +# pylint: disable=W0201 +class wmOperator(Structure): + """Defined in $source/blender/makesdna/DNA_windowmanager_types.h""" + + +# pylint: disable=W0212 +wmOperator._fields_ = [ + ("next", POINTER(wmOperator)), + ("prev", POINTER(wmOperator)), + ("idname", c_char * 64), + # IDProperty + ("properties", c_void_p), + # wmOperatorType + ("type", c_void_p), + ("customdata", c_void_p), + ("py_instance", c_void_p), + # PointerRNA + ("ptr", c_void_p), + # ReportList + ("reports", c_void_p), + ("macro", ListBase), + ("opm", POINTER(wmOperator)), + # uiLayout + ("layout", c_void_p), + ("flag", c_short), + ("_pad", c_char * 6), +] + + +# pylint: disable=W0201 +class wmEventHandler(Structure): + """Defined in $source/blender/windowmanager/wm_event_system.hh""" + + +# pylint: disable=W0212 +wmEventHandler._fields_ = [ + ("next", POINTER(wmEventHandler)), + ("prev", POINTER(wmEventHandler)), + # eWM_EventHandlerType + ("type", c_int8), + # eWM_EventHandlerFlag + ("flag", c_int8), + # EventHandlerPoll + ("poll", c_void_p), + ("op", POINTER(wmOperator)), +] diff --git a/src/screencast_keys/ops.py b/src/screencast_keys/ops.py index fef81de..834bc51 100644 --- a/src/screencast_keys/ops.py +++ b/src/screencast_keys/ops.py @@ -25,6 +25,13 @@ import collections import enum import time +# extensions.blender.org: Delete block start +from ctypes import ( + c_void_p, + cast, + POINTER, +) +# extensions.blender.org: Delete block end import blf import bpy @@ -39,6 +46,7 @@ ) from .utils.bl_class_registry import BlClassRegistry from .utils import compatibility as compat +from . import c_structure as cstruct # extensions.blender.org: Delete line from .gpu_utils import imm @@ -488,7 +496,8 @@ class SK_OT_ScreencastKeys(bpy.types.Operator): bl_idname = "wm.sk_screencast_keys" bl_label = "Screencast Keys" bl_description = "Display keys pressed" - bl_options = {'REGISTER', 'MODAL_PRIORITY'} + bl_options = {'REGISTER', 'MODAL_PRIORITY'} \ + if compat.check_version(4, 2, 0) >= 0 else {'REGISTER'} # Last save time by auto save. last_auto_saved_time = 0 @@ -1490,6 +1499,50 @@ def check_draw_status(cls, context, font_id, layer_name, calc_fn, if region_drawn: cls.draw_regions_prev.add(region.as_pointer()) + @staticmethod + def do_auto_save_before_v41(): + # extensions.blender.org: Delete block start + do_auto_save = False + for w in bpy.context.window_manager.windows: + window = cast( + c_void_p(w.as_pointer()), POINTER(cstruct.wmWindow)).contents + handler_ptr = cast( + window.modalhandlers.first, POINTER(cstruct.wmEventHandler)) + while handler_ptr: + handler = handler_ptr.contents + if handler.type == \ + cstruct.eWM_EventHandlerType.WM_HANDLER_TYPE_OP: + do_auto_save = True + op = handler.op.contents + idname = op.idname.decode() + op_prefix, op_name = idname.split("_OT_") + idname_py = "{}.{}".format(op_prefix.lower(), op_name) + if idname_py != SK_OT_ScreencastKeys.bl_idname: + debug_print(f"Modal operator '{idname_py}' is " + "running. Skip auto save") + return None + handler_ptr = cast( + handler.next, POINTER(cstruct.wmEventHandler)) + return do_auto_save + # extensions.blender.org: Delete block end + return None # pylint: disable=W0101 + + @staticmethod + def do_auto_save_after_v42(): + do_auto_save = False + wm = bpy.context.window_manager + for window in wm.windows: + for op in window.modal_operators: + idname = op.bl_idname + op_prefix, op_name = idname.split("_OT_") + idname_py = "{}.{}".format(op_prefix.lower(), op_name) + if idname_py != SK_OT_ScreencastKeys.bl_idname: + debug_print(f"Modal operator '{idname_py}' is " + "running. Skip auto save") + return None + do_auto_save = True + return do_auto_save + @staticmethod @bpy.app.handlers.persistent def auto_save(_): @@ -1511,18 +1564,12 @@ def auto_save(_): # Perform auto save only if the modal operator is executed from # Screencast Keys. - do_auto_save = False - wm = bpy.context.window_manager - for window in wm.windows: - for op in window.modal_operators: - idname = op.bl_idname - op_prefix, op_name = idname.split("_OT_") - idname_py = "{}.{}".format(op_prefix.lower(), op_name) - if idname_py != SK_OT_ScreencastKeys.bl_idname: - debug_print(f"Modal operator '{idname_py}' is " - "running. Skip auto save") - return - do_auto_save = True + if compat.check_version(4, 2, 0) < 0: + do_auto_save = cls.do_auto_save_before_v41() + else: + do_auto_save = cls.do_auto_save_after_v42() + if do_auto_save is None: + return if not do_auto_save: debug_print("No modal operator is running. Skip auto save") @@ -1594,6 +1641,74 @@ def auto_save(_): prefs.filepaths.auto_save_time = prefs.filepaths.auto_save_time cls.auto_saving = False + # extensions.blender.org: Delete block start + @staticmethod + @bpy.app.handlers.persistent + def sort_modalhandlers(_): + """Sort modalhandlers registered on wmWindow. + This makes SK_OT_ScreencastKeys.model method enable to get events + consumed by other modalhandlers.""" + + user_preferences = bpy.context.preferences + if user_preferences is None: + return + + prefs = user_preferences.addons[__package__].preferences + if not prefs.get_event_aggressively: + return + + for w in bpy.context.window_manager.windows: + window = cast( + c_void_p(w.as_pointer()), POINTER(cstruct.wmWindow)).contents + handler_ptr = cast( + window.modalhandlers.first, POINTER(cstruct.wmEventHandler)) + indices = [] + i = 0 + debug_print("====== HANDLER_LIST ======") + has_ui_handler = False + while handler_ptr: + handler = handler_ptr.contents + if handler.type == \ + cstruct.eWM_EventHandlerType.WM_HANDLER_TYPE_OP: + op = handler.op.contents + idname = op.idname.decode() + op_prefix, op_name = idname.split("_OT_") + idname_py = "{}.{}".format(op_prefix.lower(), op_name) + if idname_py == SK_OT_ScreencastKeys.bl_idname: + indices.append(i) + debug_print( + " TYPE: WM_HANDLER_TYPE_OP ({})" + .format(idname_py)) + elif handler.type == \ + cstruct.eWM_EventHandlerType.WM_HANDLER_TYPE_UI: + has_ui_handler = True + debug_print(" TYPE: WM_HANDLER_TYPE_UI") + else: + debug_print(" TYPE: {}".format(handler.type)) + + handler_ptr = cast( + handler.next, POINTER(cstruct.wmEventHandler)) + i += 1 + debug_print("==========================") + + # Blender will crash when we change the space type while Screencast + # Key is running. This issue is caused by changing order of + # WM_HANDLER_TYPE_UI handler. + # So, do nothing if there is a WM_HANDLER_TYPE_UI handler. + # TODO: Sort only WM_HANDLER_TYPE_OP handlers. + if has_ui_handler: + return + + if indices: + handlers = window.modalhandlers + for count, index in enumerate(indices): + if index != count: + prev = handlers.find(index - 2) + handler = handlers.find(index) + handlers.remove(handler) + handlers.insert_after(prev, handler) + # extensions.blender.org: Delete block end + def update_hold_modifier_keys(self, event): """Update hold modifier keys.""" @@ -1817,6 +1932,11 @@ def start(cls, self, context, event, prefs): self.origin["space"] = context.space_data.as_pointer() self.origin["region_type"] = context.region.type context.area.tag_redraw() + # extensions.blender.org: Delete block start + if prefs.get_event_aggressively: + bpy.app.handlers.depsgraph_update_pre.append( + cls.sort_modalhandlers) + # extensions.blender.org: Delete block end if prefs.auto_save: bpy.app.handlers.depsgraph_update_pre.append(cls.auto_save) @@ -1824,6 +1944,11 @@ def start(cls, self, context, event, prefs): @classmethod def stop(cls, self, context): + # extensions.blender.org: Delete block start + if cls.sort_modalhandlers in bpy.app.handlers.depsgraph_update_pre: + bpy.app.handlers.depsgraph_update_pre.remove( + cls.sort_modalhandlers) + # extensions.blender.org: Delete block end if cls.auto_save in bpy.app.handlers.depsgraph_update_pre: bpy.app.handlers.depsgraph_update_pre.remove(cls.auto_save) self.event_timer_remove(context) diff --git a/src/screencast_keys/preferences.py b/src/screencast_keys/preferences.py index 4084179..c06f9a7 100644 --- a/src/screencast_keys/preferences.py +++ b/src/screencast_keys/preferences.py @@ -31,6 +31,7 @@ from .utils.addon_updater import AddonUpdaterManager # extensions.blender.org: Delete line # noqa # pylint: disable=C0301 from .utils.bl_class_registry import BlClassRegistry from . import common +from . import c_structure as cstruct # extensions.blender.org: Delete line # extensions.blender.org: Delete block start @@ -395,6 +396,15 @@ class SK_Preferences(bpy.types.AddonPreferences): default='LABEL_AND_IDNAME', ) + # extensions.blender.org: Delete block start + get_event_aggressively: bpy.props.BoolProperty( + name="Get Event Aggressively", + description="(Experimental) Get events which will be dropped by the" + "other modalhandlers. This may make blender unstable", + default=not cstruct.NOT_SUPPORTED, + ) + # extensions.blender.org: Delete block end + auto_save: bpy.props.BoolProperty( name="Auto Save", description="(Experimental) Enable custom auto save while modal " @@ -497,14 +507,14 @@ def ui_in_overlay_update_fn(self, _): type=DisplayEventTextAliasProperties ) -# extensions.blender.org: Delete block start + # extensions.blender.org: Delete block start # for add-on updater updater_branch_to_update: EnumProperty( name="branch", description="Target branch to update add-on", items=get_update_candidate_branches ) -# extensions.blender.org: Delete block end + # extensions.blender.org: Delete block end def draw(self, _): layout = self.layout @@ -649,6 +659,7 @@ def draw(self, _): layout.label(text="Experimental:") col = layout.column() + col.prop(self, "get_event_aggressively") # extensions.blender.org: Delete line # noqa # pylint: disable=C0301 col.prop(self, "auto_save") layout.separator() @@ -689,7 +700,7 @@ def draw(self, _): col = sp.column() col.prop(d, "alias_text", text="") -# extensions.blender.org: Delete block start + # extensions.blender.org: Delete block start elif self.category == 'UPDATE': updater = AddonUpdaterManager.get_instance() @@ -739,4 +750,4 @@ def draw(self, _): elif updater.has_info(): box = layout.box() box.label(text=updater.info(), icon='ERROR') -# extensions.blender.org: Delete block end + # extensions.blender.org: Delete block end diff --git a/src/screencast_keys/ui.py b/src/screencast_keys/ui.py index 87824db..b9369c4 100644 --- a/src/screencast_keys/ui.py +++ b/src/screencast_keys/ui.py @@ -122,6 +122,20 @@ def draw(self, _): c.label(text="Mode:") c.prop(prefs, "last_operator_show_mode", text="") + # extensions.blender.org: Delete block start + + column.separator() + + column.label(text="Experimental:") + column.column() + sp = column.split(factor=0.05) + _ = sp.column() # spacer. + sp = sp.split(factor=1.0) + c = sp.column() + c.prop(prefs, "get_event_aggressively") + + # extensions.blender.org: Delete block end + class SK_PT_ScreencastKeys_Overlay(bpy.types.Panel): bl_label = "" diff --git a/src/screencast_keys/utils/compatibility.py b/src/screencast_keys/utils/compatibility.py index 48a8704..6e5f718 100644 --- a/src/screencast_keys/utils/compatibility.py +++ b/src/screencast_keys/utils/compatibility.py @@ -32,6 +32,8 @@ def check_version(major, minor, _): return 0 if bpy.app.version[0] > major: return 1 + if bpy.app.version[0] < major: + return -1 if bpy.app.version[1] > minor: return 1 return -1 diff --git a/tests/python/screencast_keys_test/common.py b/tests/python/screencast_keys_test/common.py index 143aa5a..a3832c4 100644 --- a/tests/python/screencast_keys_test/common.py +++ b/tests/python/screencast_keys_test/common.py @@ -17,6 +17,8 @@ def check_version(major, minor, _): return 0 if bpy.app.version[0] > major: return 1 + if bpy.app.version[0] < major: + return -1 if bpy.app.version[1] > minor: return 1 return -1 @@ -30,23 +32,31 @@ def get_user_preferences(context): def check_addon_enabled(mod): - if check_version(2, 80, 0) < 0: + if check_version(2, 80, 0) >= 0: + result = bpy.ops.preferences.addon_enable(module=mod) + else: result = bpy.ops.wm.addon_enable(module=mod) + assert (result == {'FINISHED'}), "Failed to enable add-on {}".format(mod) + if check_version(2, 80, 0) >= 0: + assert mod in bpy.context.preferences.addons.keys(),\ + "Failed to enable add-on {}".format(mod) else: - result = bpy.ops.preferences.addon_enable(module=mod) - assert (result == {'FINISHED'}), "Failed to enable add-on %s" % (mod) - assert (mod in get_user_preferences(bpy.context).addons.keys()), \ - "Failed to enable add-on %s" % (mod) + assert mod in bpy.context.user_preferences.addons.keys(),\ + "Failed to enable add-on {}".format(mod) def check_addon_disabled(mod): - if check_version(2, 80, 0) < 0: + if check_version(2, 80, 0) >= 0: + result = bpy.ops.preferences.addon_disable(module=mod) + else: result = bpy.ops.wm.addon_disable(module=mod) + assert (result == {'FINISHED'}), "Failed to disable add-on {}".format(mod) + if check_version(2, 80, 0) >= 0: + assert mod not in bpy.context.preferences.addons.keys(),\ + "Failed to disable add-on {}".format(mod) else: - result = bpy.ops.preferences.addon_disable(module=mod) - assert (result == {'FINISHED'}), "Failed to disable add-on %s" % (mod) - assert (mod not in get_user_preferences(bpy.context).addons.keys()), \ - "Failed to disable add-on %s" % (mod) + assert mod not in bpy.context.user_preferences.addons.keys(),\ + "Failed to disable add-on {}".format(mod) def operator_exists(idname): @@ -84,13 +94,16 @@ def preferences_exists(name): class TestBase(unittest.TestCase): - package_name = "bl_ext.user_default.screencast_keys" + package_name = "screencast_keys" module_name = "" submodule_name = None idname = [] @classmethod def setUpClass(cls): + if check_version(4, 2, 0) >= 0: + cls.package_name = "bl_ext.user_default." + cls.package_name + if cls.submodule_name is not None: print("\n======== Module Test: {}.{} ({}) ========" .format(cls.package_name, cls.module_name, diff --git a/tools/remove_code_extensions.blender.org.sh b/tools/remove_code_extensions.blender.org.sh index 6ddb25a..f701751 100644 --- a/tools/remove_code_extensions.blender.org.sh +++ b/tools/remove_code_extensions.blender.org.sh @@ -19,6 +19,7 @@ TMP_DIR=$(mktemp -d) REMOVE_FILES=( "screencast_keys/utils/addon_updater.py" + "screencast_keys/c_structure/.*.py" ) mkdir -p "${OUTPUT_DIR}"