Welcome to mirror list, hosted at ThFree Co, Russian Federation.

platform_helpers.py « bl_keymap_utils « modules « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 848eb4e10c454a85856333cbf921d4313deb798b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# ##### 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 #####


def keyconfig_data_oskey_from_ctrl(keyconfig_data_src, *, filter_fn=None):
    keyconfig_data_dst = []
    for km_name, km_parms, km_items_data_src in keyconfig_data_src:
        km_items_data_dst = km_items_data_src.copy()
        items_dst = []
        km_items_data_dst["items"] = items_dst
        for item_src in km_items_data_src["items"]:
            item_op, item_event, item_prop = item_src
            if "ctrl" in item_event:
                if filter_fn is None or filter_fn(item_event):
                    item_event = item_event.copy()
                    item_event["oskey"] = item_event["ctrl"]
                    del item_event["ctrl"]
                    items_dst.append((item_op, item_event, item_prop))
            items_dst.append(item_src)
        keyconfig_data_dst.append((km_name, km_parms, km_items_data_dst))
    return keyconfig_data_dst


def keyconfig_data_oskey_from_ctrl_for_macos(keyconfig_data_src):
    """Use for apple since Cmd is typically used in-place of Ctrl."""
    def filter_fn(item_event):
        if item_event.get("ctrl"):
            event_type = item_event["type"]
            # Ctrl-{Key}
            if (event_type in {
                    'H',
                    'M',
                    'SPACE',
                    'W',
                    'ACCENT_GRAVE',
                    'PERIOD',
                    'TAB',
            }):
                if (not item_event.get("alt")) and (not item_event.get("shift")):
                    return False
            # Ctrl-Alt-{Key}
            if (event_type in {
                    'Q',
            }):
                if item_event.get("alt") and (not item_event.get("shift")):
                    return False
        return True

    return keyconfig_data_oskey_from_ctrl(keyconfig_data_src, filter_fn=filter_fn)