Skip to content

Commit

Permalink
Use Ctrl+Alt+number for function keys in certain cases on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
samkusin committed Aug 16, 2023
1 parent 502b838 commit 2f938a2
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 63 deletions.
18 changes: 10 additions & 8 deletions host/clem_front.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,11 +1425,12 @@ void ClemensFrontend::doMainMenu(ImVec2 &anchor, ClemensHostInterop &interop) {
}
}
ImGui::Separator();
if (ImGui::MenuItem("Fast Mode", CLEM_L10N_LABEL(kFastModeShortCutText), interop.fastMode, isBackendRunning())) {
if (ImGui::MenuItem("Fast Mode", CLEM_L10N_LABEL(kFastModeShortCutText),
interop.fastMode, isBackendRunning())) {
if (interop.fastMode) {
interop.action = ClemensHostInterop::DisableFastMode;
} else {
interop.action = ClemensHostInterop::EnableFastMode;
interop.action = ClemensHostInterop::EnableFastMode;
}
}
if (ImGui::MenuItem("Configure Joystick", NULL, false,
Expand Down Expand Up @@ -1462,22 +1463,23 @@ void ClemensFrontend::doMainMenu(ImVec2 &anchor, ClemensHostInterop &interop) {
if (guiMode_ == GUIMode::Emulator) {
if (ImGui::IsKeyDown(ImGuiKey_LeftAlt)) {
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl)) {
if (ImGui::IsKeyPressed(ImGuiKey_F10)) {
if (ImGui::IsKeyPressed(ImGuiKey_F10) || ImGui::IsKeyPressed(ImGuiKey_0)) {
if (interop.mouseLock) {
interop.action = ClemensHostInterop::MouseUnlock;
} else {
interop.action = ClemensHostInterop::MouseLock;
}
} else if (ImGui::IsKeyPressed(ImGuiKey_F11)) {
} else if (ImGui::IsKeyPressed(ImGuiKey_F11) ||
ImGui::IsKeyPressed(ImGuiKey_Minus)) {
config_.hybridInterfaceEnabled = !config_.hybridInterfaceEnabled;
config_.setDirty();
} else if (ImGui::IsKeyPressed(ImGuiKey_F5)) {
} else if (ImGui::IsKeyPressed(ImGuiKey_F5) || ImGui::IsKeyPressed(ImGuiKey_5)) {
if (frameReadState_.isRunning) {
interop.action = ClemensHostInterop::PauseExecution;
} else {
interop.action = ClemensHostInterop::ContinueExecution;
}
} else if (ImGui::IsKeyPressed(ImGuiKey_F8)) {
} else if (ImGui::IsKeyPressed(ImGuiKey_F8) || ImGui::IsKeyPressed(ImGuiKey_8)) {
if (lastCommandState_.isFastModeOn) {
interop.action = ClemensHostInterop::DisableFastMode;
} else {
Expand Down Expand Up @@ -1729,7 +1731,7 @@ void ClemensFrontend::doInfoStatusLayout(ImVec2 anchor, ImVec2 dimensions, float
}
ClemensHostImGui::StatusBarField(isResetDown ? ClemensHostImGui::StatusBarFlags_Active
: ClemensHostImGui::StatusBarFlags_Inactive,
"%5.2f mhz",runSpeedMhz);
"%5.2f mhz", runSpeedMhz);

ImGui::SameLine(anchor.x + dimensions.x - resetStatusWidth);
ClemensHostImGui::StatusBarField(isResetDown ? ClemensHostImGui::StatusBarFlags_Active
Expand Down Expand Up @@ -3188,7 +3190,7 @@ void ClemensFrontend::doJoystickConfig(ImVec2 anchor, ImVec2 dimensions) {
// two rows, one per joystick
// buttons 1 and 2 require mapping controls
for (unsigned joystickIndex = 0; joystickIndex < joystickSlotCount_; joystickIndex++) {
char joyId[8];
char joyId[16];
snprintf(joyId, sizeof(joyId) - 1, "joy%u", joystickIndex);
auto &bindings = config_.joystickBindings[joystickIndex];
auto &joystick = joysticks_[joystickIndex];
Expand Down
64 changes: 37 additions & 27 deletions host/clem_host_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ static ClemensHostInterop g_interop{};
#if defined(CLEMENS_APP_ICONS_ARE_RESIDENT)
#include "images/app_icons_png.h"

void loadAppIcon(sapp_image_desc* desc, const uint8_t *src, const unsigned srcLen) {
desc->pixels.ptr = ClemensHostAssets::loadBitmapFromPNG(
src, srcLen, &desc->width, &desc->height);
void loadAppIcon(sapp_image_desc *desc, const uint8_t *src, const unsigned srcLen) {
desc->pixels.ptr =
ClemensHostAssets::loadBitmapFromPNG(src, srcLen, &desc->width, &desc->height);
if (!desc->pixels.ptr) {
return;
}
Expand Down Expand Up @@ -128,31 +128,33 @@ static sapp_keycode onKeyUp(const sapp_event *evt, bool *doDownEvent) {
return evt->key_code;
}
#elif defined(CLEMENS_PLATFORM_LINUX)
// The Super/Tux key seems special-cased in Linux to bypass X Windows keyboard
// shortcuts involving CTRL and ALT. To prevent accidental triggering of
// disruptive shortcut keys like ALT-Fx, the Super Key must be used in-tandem
// with CTRL or ALT key down events before passing the event to the emulator.
// As a side effect, ALT-Fx cannot be supported on X Windows -
// Linux, Alt and function keys makes emulation tricky
// Solution: When either Ctrl or ALt are pressed, number keys are translated
// to function keys and remain so until the number key is released
// (g_fnKeys[n] = 0 for up, 1 = down)
//
// SO: if Super Key is Down, Fx keys are remapped to 1 - 0, to avoid
// conflicts between CTRL+ALT+Fx key presses.
// delete key also maps to F12
//
static bool g_leftSuperKeyDown = false;
static bool g_rightSuperKeyDown = false;
static bool g_leftAltKeyDown = false;
static bool g_leftCtrlKeyDown = false;
static bool g_rightAltKeyDown = false;
static bool g_rightCtrlKeyDown = false;
static bool g_escapeKeyDown = false;
static bool g_fnKeys[12];

static sapp_keycode onKeyDown(const sapp_event *evt) {
sapp_keycode outKeyCode = evt->key_code;

if (!g_leftSuperKeyDown && evt->key_code == SAPP_KEYCODE_LEFT_SUPER)
g_leftSuperKeyDown = true;
if (!g_rightSuperKeyDown && evt->key_code == SAPP_KEYCODE_RIGHT_SUPER)
g_rightSuperKeyDown = true;
if (!g_leftAltKeyDown && evt->key_code == SAPP_KEYCODE_LEFT_ALT)
g_leftAltKeyDown = true;
if (!g_rightAltKeyDown && evt->key_code == SAPP_KEYCODE_RIGHT_ALT)
g_rightAltKeyDown = true;
if (!g_leftCtrlKeyDown && evt->key_code == SAPP_KEYCODE_LEFT_CONTROL)
g_leftCtrlKeyDown = true;
if (!g_rightCtrlKeyDown && evt->key_code == SAPP_KEYCODE_RIGHT_CONTROL)
g_rightCtrlKeyDown = true;

int fnKey = xlatToFnKey(evt);
if (g_leftSuperKeyDown || g_rightSuperKeyDown) {
if (g_leftAltKeyDown || g_leftCtrlKeyDown || g_rightAltKeyDown || g_rightCtrlKeyDown) {
if (fnKey > 0) {
g_fnKeys[fnKey - 1] = true;
outKeyCode = static_cast<sapp_keycode>(static_cast<int>(SAPP_KEYCODE_F1) + (fnKey - 1));
Expand All @@ -174,13 +176,17 @@ static sapp_keycode onKeyDown(const sapp_event *evt) {
static sapp_keycode onKeyUp(const sapp_event *evt, bool *doDownEvent) {
sapp_keycode outKeyCode = evt->key_code;

if (g_leftSuperKeyDown && evt->key_code == SAPP_KEYCODE_LEFT_SUPER)
g_leftSuperKeyDown = false;
else if (g_rightSuperKeyDown && evt->key_code == SAPP_KEYCODE_RIGHT_SUPER)
g_leftSuperKeyDown = false;
if (g_leftAltKeyDown && evt->key_code == SAPP_KEYCODE_LEFT_ALT)
g_leftAltKeyDown = false;
else if (g_rightAltKeyDown && evt->key_code == SAPP_KEYCODE_RIGHT_ALT)
g_rightAltKeyDown = false;
if (g_leftCtrlKeyDown && evt->key_code == SAPP_KEYCODE_LEFT_CONTROL)
g_leftCtrlKeyDown = false;
else if (g_rightAltKeyDown && evt->key_code == SAPP_KEYCODE_RIGHT_CONTROL)
g_rightCtrlKeyDown = false;

int fnKey = xlatToFnKey(evt);
if (fnKey > 0) {
if (fnKey > 0 && g_fnKeys[fnKey - 1]) {
g_fnKeys[fnKey - 1] = false;
outKeyCode = static_cast<sapp_keycode>(static_cast<int>(SAPP_KEYCODE_F1) + (fnKey - 1));
}
Expand Down Expand Up @@ -626,10 +632,14 @@ sapp_desc sokol_main(int argc, char *argv[]) {
sapp.logger.func = sokolLogger;
sapp.clipboard_size = kClipboardTextLimit;

loadAppIcon(&sapp.icon.images[0], app_icon_cinekine_Clemens_16_png, app_icon_cinekine_Clemens_16_png_len);
loadAppIcon(&sapp.icon.images[1], app_icon_cinekine_Clemens_32_png, app_icon_cinekine_Clemens_32_png_len);
loadAppIcon(&sapp.icon.images[2], app_icon_cinekine_Clemens_64_png, app_icon_cinekine_Clemens_64_png_len);
loadAppIcon(&sapp.icon.images[3], app_icon_cinekine_Clemens_128_png, app_icon_cinekine_Clemens_128_png_len);
loadAppIcon(&sapp.icon.images[0], app_icon_cinekine_Clemens_16_png,
app_icon_cinekine_Clemens_16_png_len);
loadAppIcon(&sapp.icon.images[1], app_icon_cinekine_Clemens_32_png,
app_icon_cinekine_Clemens_32_png_len);
loadAppIcon(&sapp.icon.images[2], app_icon_cinekine_Clemens_64_png,
app_icon_cinekine_Clemens_64_png_len);
loadAppIcon(&sapp.icon.images[3], app_icon_cinekine_Clemens_128_png,
app_icon_cinekine_Clemens_128_png_len);

return sapp;
}
57 changes: 29 additions & 28 deletions host/strings/clem_hotkeys.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@
const char *kGSKeyboardCommands[] = {R"md(
## Mouse Control
Currently to use the mouse in a IIGS application, the emulator locks the mouse to the view (i.e. mouselock.)
The emulator attempts to seamlessly integrate mouse movement between the Apple IIGS and your desktop.
To transfer control of the mouse to the IIGS session, click within the view. To exit the view, follow the instructions shown in the bottom of the view. This instruction is also detailed in the Key Bindings section.
There may be titles where this mouse emulation does not work. In those cases, the user can lock mouse input to the IIGS screen. See the hotkey help for details.
## Key Bindings
The Tux/Super key when combined with number keys will treat them as function keys. For example:
- Tux + 1 = F1
- Tux + 2 = F2
- Tux + Minus = F11
- Tux + Equals = F12
- Tux + Ctrl + Equals = CTRL-RESET
- Tux + Ctrl + Alt + Equals = CTRL-ALT-RESET (reboot)
- Tux + Ctrl + Left Alt + 1 to enter the Control Panel
- Tux + Ctrl + Left Alt + Minus to switch to Debugger Mode
- Tux + Ctrl + Alt + F10 to lock the mouse
- Ctrl + F12 = CTRL-RESET
- Ctrl + Alt + Equals = CTRL-ALT-RESET (reboot)
- Ctrl + Left Alt + 1 to enter the Control Panel
- Ctrl + Left Alt + Minus to switch to Debugger Mode
- Ctrl + Alt + F10 to lock the mouse
- Ctrl + Alt + F8 to toggle fast mode
- Ctrl + Alt + F5 to pause and resume emulation
)md"};
const char *kMouseUnlock[] = {"Press Tux, Ctrl, Alt and F10 to unlock mouse"};
const char *kMouseUnlock[] = {"Press Ctrl + Alt + 0 to unlock mouse"};

const char *kHybridModeShortcutText[]= {"Tux+Ctrl+LAlt+minus"};
const char *kLockMouseShortcutText[]={"Tux+Ctrl+LAlt+F10"};
const char *kTogglePauseShortcutText[]={"Tux+Ctrl+LAlt+5"};
const char *kFastModeShortCutText[] = {"Tux+Ctrl+Lalt+8"};
const char *kHybridModeShortcutText[] = {"Ctrl + LAlt + minus"};
const char *kLockMouseShortcutText[] = {"Ctrl + LAlt + 0"};
const char *kTogglePauseShortcutText[] = {"Ctrl + LAlt + 5"};
const char *kFastModeShortCutText[] = {"Ctrl + LAlt + 8"};

#elif defined(__APPLE__)
const char *kGSKeyboardCommands[] = {R"md(
Expand All @@ -43,32 +39,37 @@ There may be titles where this mouse emulation does not work. In those cases, t
- Ctrl + Option + F1 to enter the Control Panel
- Ctrl + Option + F11 to switch to Debugger Mode
- Ctrl + Option + F10 to lock mouse
- Ctrl + Option + F8 to toggle fast mode
- Ctrl + Option + F5 to pause and resume emulation
)md"};
const char *kMouseUnlock[] = {"Press CTRL + Option + F10 to unlock mouse"};

// UNUSED since these are handled outside of ImGUI
const char *kHybridModeShortcutText[]= {"Ctrl + Option + F11"};
const char *kLockMouseShortcutText[]={"Ctrl + Option+ F10"};
const char *kTogglePauseShortcutText[]={"Ctrl + Option + F5"};
const char *kHybridModeShortcutText[] = {"Ctrl + Option + F11"};
const char *kLockMouseShortcutText[] = {"Ctrl + Option+ F10"};
const char *kTogglePauseShortcutText[] = {"Ctrl + Option + F5"};
const char *kFastModeShortCutText[] = {"Ctrl + Option + F8"};
#else
const char *kGSKeyboardCommands[] = {R"md(
## Mouse Control
Currently to use the mouse in a IIGS application, the emulator locks the mouse to the view (i.e. mouselock.)
The emulator attempts to seamlessly integrate mouse movement between the Apple IIGS and your desktop.
To transfer control of the mouse to the IIGS session, click within the view. To exit the view, follow the instructions shown in the bottom of the view. This instruction is also detailed in the Key Bindings section.
There may be titles where this mouse emulation does not work. In those cases, the user can lock mouse input to the IIGS screen. See the hotkey help for details.
- Ctrl-Right ALT-F12 to reboot the system
- Ctrl-F12 for CTRL-RESET
- Ctrl-Left ALT-F1 to enter the Control Panel
- Ctrl-Left ALT-F11 to switch to Debugger Mode
- Ctrl-Left ALT-F10 to lock mouse)md"};
- Ctrl-Left ALT-F10 to lock mouse
- Ctrl-Left ALT-F8 to toggle fast mode
- Ctrl-Left ALT-F5 to pause and resume emulation
)md"};
const char *kMouseUnlock[] = {"Press CTRL + ALT + F10 to unlock mouse"};

const char *kHybridModeShortcutText[]= {"Ctrl + Left Alt + F11"};
const char *kLockMouseShortcutText[]={"Ctrl + Left Alt + F10"};
const char *kTogglePauseShortcutText[]={"Ctrl + Left Alt + F5"};
const char *kFastModeShortCutText[]={"Ctrl + Left Alt + F8"};
const char *kHybridModeShortcutText[] = {"Ctrl + Left Alt + F11"};
const char *kLockMouseShortcutText[] = {"Ctrl + Left Alt + F10"};
const char *kTogglePauseShortcutText[] = {"Ctrl + Left Alt + F5"};
const char *kFastModeShortCutText[] = {"Ctrl + Left Alt + F8"};
#endif

0 comments on commit 2f938a2

Please sign in to comment.