Adds the following registry options, which configure the Mac driver to map Command to Ctrl:
HKEY_CURRENT_USER\Software\Wine\Mac Driver\LeftCommandIsCtrl HKEY_CURRENT_USER\Software\Wine\Mac Driver\RightCommandIsCtrl
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=35351 Signed-off-by: Ricky Zhou ricky@rzhou.org --- dlls/winemac.drv/cocoa_window.m | 38 ++++++++++++++++++++------------- dlls/winemac.drv/macdrv_cocoa.h | 2 ++ dlls/winemac.drv/macdrv_main.c | 7 ++++++ 3 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m index 4143d147df..6eacf43151 100644 --- a/dlls/winemac.drv/cocoa_window.m +++ b/dlls/winemac.drv/cocoa_window.m @@ -140,22 +140,30 @@ static inline void fix_generic_modifiers_by_device(NSUInteger* modifiers) *modifiers &= ~NX_ALTERNATEMASK; }
-static inline NSUInteger adjusted_modifiers_for_option_behavior(NSUInteger modifiers) +static inline NSUInteger adjusted_modifiers_for_settings(NSUInteger modifiers) { fix_device_modifiers_by_generic(&modifiers); - if (left_option_is_alt && (modifiers & NX_DEVICELALTKEYMASK)) - { - modifiers |= NX_DEVICELCMDKEYMASK; - modifiers &= ~NX_DEVICELALTKEYMASK; - } - if (right_option_is_alt && (modifiers & NX_DEVICERALTKEYMASK)) - { - modifiers |= NX_DEVICERCMDKEYMASK; - modifiers &= ~NX_DEVICERALTKEYMASK; - } - fix_generic_modifiers_by_device(&modifiers); + NSUInteger new_modifiers = modifiers & ~(NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK | + NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK);
- return modifiers; + // The MACDRV keyboard driver translates Alt modifiers in hotkeys to + // Command. For example, a call to user32!RegisterHotKey for Alt-c + // translates to a call to RegisterEventHotKey for Command-c. + // + // If the Option modifier should behave like Alt in Windows, rewrite + // it to Command. + if (modifiers & NX_DEVICELALTKEYMASK) + new_modifiers |= left_option_is_alt ? NX_DEVICELCMDKEYMASK : NX_DEVICELALTKEYMASK; + if (modifiers & NX_DEVICERALTKEYMASK) + new_modifiers |= right_option_is_alt ? NX_DEVICERCMDKEYMASK : NX_DEVICERALTKEYMASK; + + if (modifiers & NX_DEVICELCMDKEYMASK) + new_modifiers |= left_command_is_ctrl ? NX_DEVICELCTLKEYMASK : NX_DEVICELCMDKEYMASK; + if (modifiers & NX_DEVICERCMDKEYMASK) + new_modifiers |= right_command_is_ctrl ? NX_DEVICERCTLKEYMASK : NX_DEVICERCMDKEYMASK; + + fix_generic_modifiers_by_device(&new_modifiers); + return new_modifiers; }
@@ -2059,7 +2067,7 @@ - (void) postKeyEvent:(NSEvent *)theEvent [self flagsChanged:theEvent]; [self postKey:[theEvent keyCode] pressed:[theEvent type] == NSKeyDown - modifiers:adjusted_modifiers_for_option_behavior([theEvent modifierFlags]) + modifiers:adjusted_modifiers_for_settings([theEvent modifierFlags]) event:theEvent]; }
@@ -2679,7 +2687,7 @@ - (void) flagsChanged:(NSEvent *)theEvent { NX_DEVICERCMDKEYMASK, kVK_RightCommand }, };
- NSUInteger modifierFlags = adjusted_modifiers_for_option_behavior([theEvent modifierFlags]); + NSUInteger modifierFlags = adjusted_modifiers_for_settings([theEvent modifierFlags]); NSUInteger changed; int i, last_changed;
diff --git a/dlls/winemac.drv/macdrv_cocoa.h b/dlls/winemac.drv/macdrv_cocoa.h index 6bad7903f6..011b1ffd37 100644 --- a/dlls/winemac.drv/macdrv_cocoa.h +++ b/dlls/winemac.drv/macdrv_cocoa.h @@ -159,6 +159,8 @@ extern int capture_displays_for_fullscreen DECLSPEC_HIDDEN; extern int left_option_is_alt DECLSPEC_HIDDEN; extern int right_option_is_alt DECLSPEC_HIDDEN; +extern int left_command_is_ctrl DECLSPEC_HIDDEN; +extern int right_command_is_ctrl DECLSPEC_HIDDEN; extern int allow_immovable_windows DECLSPEC_HIDDEN; extern int cursor_clipping_locks_windows DECLSPEC_HIDDEN; extern int use_precise_scrolling DECLSPEC_HIDDEN; diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c index 7abeea9db8..8759e58641 100644 --- a/dlls/winemac.drv/macdrv_main.c +++ b/dlls/winemac.drv/macdrv_main.c @@ -52,6 +52,8 @@ BOOL allow_vsync = TRUE; BOOL allow_set_gamma = TRUE; int left_option_is_alt = 0; int right_option_is_alt = 0; +int left_command_is_ctrl = 0; +int right_command_is_ctrl = 0; BOOL allow_software_rendering = FALSE; BOOL disable_window_decorations = FALSE; int allow_immovable_windows = TRUE; @@ -172,6 +174,11 @@ static void setup_options(void) if (!get_config_key(hkey, appkey, "RightOptionIsAlt", buffer, sizeof(buffer))) right_option_is_alt = IS_OPTION_TRUE(buffer[0]);
+ if (!get_config_key(hkey, appkey, "LeftCommandIsCtrl", buffer, sizeof(buffer))) + left_command_is_ctrl = IS_OPTION_TRUE(buffer[0]); + if (!get_config_key(hkey, appkey, "RightCommandIsCtrl", buffer, sizeof(buffer))) + right_command_is_ctrl = IS_OPTION_TRUE(buffer[0]); + if (!get_config_key(hkey, appkey, "AllowSoftwareRendering", buffer, sizeof(buffer))) allow_software_rendering = IS_OPTION_TRUE(buffer[0]);
Hi,
On Sep 10, 2018, at 2:21 AM, Ricky Zhou ricky@rzhou.org wrote:
Adds the following registry options, which configure the Mac driver to map Command to Ctrl:
HKEY_CURRENT_USER\Software\Wine\Mac Driver\LeftCommandIsCtrl HKEY_CURRENT_USER\Software\Wine\Mac Driver\RightCommandIsCtrl
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=35351 Signed-off-by: Ricky Zhou ricky@rzhou.org
dlls/winemac.drv/cocoa_window.m | 38 ++++++++++++++++++++------------- dlls/winemac.drv/macdrv_cocoa.h | 2 ++ dlls/winemac.drv/macdrv_main.c | 7 ++++++ 3 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m index 4143d147df..6eacf43151 100644 --- a/dlls/winemac.drv/cocoa_window.m +++ b/dlls/winemac.drv/cocoa_window.m @@ -140,22 +140,30 @@ static inline void fix_generic_modifiers_by_device(NSUInteger* modifiers) *modifiers &= ~NX_ALTERNATEMASK; }
-static inline NSUInteger adjusted_modifiers_for_option_behavior(NSUInteger modifiers) +static inline NSUInteger adjusted_modifiers_for_settings(NSUInteger modifiers) { fix_device_modifiers_by_generic(&modifiers);
- if (left_option_is_alt && (modifiers & NX_DEVICELALTKEYMASK))
- {
modifiers |= NX_DEVICELCMDKEYMASK;
modifiers &= ~NX_DEVICELALTKEYMASK;
- }
- if (right_option_is_alt && (modifiers & NX_DEVICERALTKEYMASK))
- {
modifiers |= NX_DEVICERCMDKEYMASK;
modifiers &= ~NX_DEVICERALTKEYMASK;
- }
- fix_generic_modifiers_by_device(&modifiers);
- NSUInteger new_modifiers = modifiers & ~(NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK |
NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK);
- return modifiers;
- // The MACDRV keyboard driver translates Alt modifiers in hotkeys to
- // Command. For example, a call to user32!RegisterHotKey for Alt-c
- // translates to a call to RegisterEventHotKey for Command-c.
- //
- // If the Option modifier should behave like Alt in Windows, rewrite
- // it to Command.
I'm a bit confused about why you added this comment here.
On the one hand, you're right that RegisterHotKey() translates Alt to Command, but that's not related to this code. It is a bug in that, if the user has set LeftOptionIsAlt, we probably want to use optionKey for MOD_ALT in macdrv_RegisterHotKey(), either instead of cmdKey (if LeftCommandIsCtrl is set) or combined with cmdKey (if not). If LeftCommandIsCtrl, we probably want to use cmdKey | controlKey for MOD_CONTROL. That is, we want to register the hot key with the Mac modifiers being the same as what the user would/could type in a Wine app to get the specified Win32 modifiers.
But none of the code here is related to hot keys. It's just implementing the registry setting.
- if (modifiers & NX_DEVICELALTKEYMASK)
new_modifiers |= left_option_is_alt ? NX_DEVICELCMDKEYMASK : NX_DEVICELALTKEYMASK;
- if (modifiers & NX_DEVICERALTKEYMASK)
new_modifiers |= right_option_is_alt ? NX_DEVICERCMDKEYMASK : NX_DEVICERALTKEYMASK;
- if (modifiers & NX_DEVICELCMDKEYMASK)
new_modifiers |= left_command_is_ctrl ? NX_DEVICELCTLKEYMASK : NX_DEVICELCMDKEYMASK;
- if (modifiers & NX_DEVICERCMDKEYMASK)
new_modifiers |= right_command_is_ctrl ? NX_DEVICERCTLKEYMASK : NX_DEVICERCMDKEYMASK;
- fix_generic_modifiers_by_device(&new_modifiers);
- return new_modifiers;
}
diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c index 7abeea9db8..8759e58641 100644 --- a/dlls/winemac.drv/macdrv_main.c +++ b/dlls/winemac.drv/macdrv_main.c @@ -52,6 +52,8 @@ BOOL allow_vsync = TRUE; BOOL allow_set_gamma = TRUE; int left_option_is_alt = 0; int right_option_is_alt = 0; +int left_command_is_ctrl = 0; +int right_command_is_ctrl = 0; BOOL allow_software_rendering = FALSE; BOOL disable_window_decorations = FALSE; int allow_immovable_windows = TRUE; @@ -172,6 +174,11 @@ static void setup_options(void) if (!get_config_key(hkey, appkey, "RightOptionIsAlt", buffer, sizeof(buffer))) right_option_is_alt = IS_OPTION_TRUE(buffer[0]);
- if (!get_config_key(hkey, appkey, "LeftCommandIsCtrl", buffer, sizeof(buffer)))
left_command_is_ctrl = IS_OPTION_TRUE(buffer[0]);
- if (!get_config_key(hkey, appkey, "RightCommandIsCtrl", buffer, sizeof(buffer)))
right_command_is_ctrl = IS_OPTION_TRUE(buffer[0]);
Hmm. If a user sets LeftCommandIsCtrl and RightCommandIsCtrl but neither of LeftOptionIsAlt nor RightOptionIsAlt, then they have no way of typing the Windows Alt key. The Option keys will access additional characters from the keyboard layout and the Command keys will send Ctrl. That's probably worth at least a warning message.
-Ken
On Tue, Sep 11, 2018 at 11:50 AM Ken Thomases ken@codeweavers.com wrote:
I'm a bit confused about why you added this comment here.
On the one hand, you're right that RegisterHotKey() translates Alt to Command, but that's not related to this code. It is a bug in that, if the user has set LeftOptionIsAlt, we probably want to use optionKey for MOD_ALT in macdrv_RegisterHotKey(), either instead of cmdKey (if LeftCommandIsCtrl is set) or combined with cmdKey (if not). If LeftCommandIsCtrl, we probably want to use cmdKey | controlKey for MOD_CONTROL. That is, we want to register the hot key with the Mac modifiers being the same as what the user would/could type in a Wine app to get the specified Win32 modifiers.
But none of the code here is related to hot keys. It's just implementing the registry setting.
Ah, you're right, the hotkeys comment didn't make any sense here. My intent was to clarify why rewriting Option to Alt is done by rewriting it to Command - I've reworded the comment.
Regarding the global hotkeys bug - I unfortunately don't have a great idea for a fix. RegisterEventHotKey does not provide a way to distinguish between the left or right modifiers. This means that there isn't a way to register a correct hotkey with Ctrl when LeftCommandIsCtrl is true and RightCommandIsCtrl is false. I wonder if it might make sense to have a separate configurable mapping for global hotkeys (though maybe that can be done separately from this change?)
Hmm. If a user sets LeftCommandIsCtrl and RightCommandIsCtrl but neither of LeftOptionIsAlt nor RightOptionIsAlt, then they have no way of typing the Windows Alt key. The Option keys will access additional characters from the keyboard layout and the Command keys will send Ctrl. That's probably worth at least a warning message.
Added a warning.
Thanks, Ricky