Skip to content

Commit

Permalink
game menu: add toggle keyboard and toggle mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
Karim Mreisi committed Feb 15, 2023
1 parent 2772ab1 commit c9fe96a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
17 changes: 16 additions & 1 deletion app/src/main/java/com/limelight/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,15 @@ public void toggleKeyboard() {
inputManager.toggleSoftInput(0, 0);
}

public boolean isMouseEmulationActive() {
return controllerHandler.isMouseEmulationEnabled();
}

public void toggleMouseEmulation() {
controllerHandler.toggleMouseEmulation();
}


// Returns true if the event was consumed
// NB: View is only present if called from a view callback
private boolean handleMotionEvent(View view, MotionEvent event) {
Expand Down Expand Up @@ -2260,6 +2269,12 @@ public void onUsbPermissionPromptCompleted() {
updatePipAutoEnter();
}


@Override
public void showGameMenu() {
new GameMenu(this, conn);
}

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
switch (keyEvent.getAction()) {
Expand All @@ -2271,7 +2286,7 @@ public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
// Intercept back key event before android handles it
// Always handle the request, the user has to select "Disconnect" within the game menu to actually disconnect
if (keyCode == keyEvent.KEYCODE_BACK) {
new GameMenu(this, conn);
showGameMenu();
return true;
}
case KeyEvent.ACTION_UP:
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/limelight/GameMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ private void sendKeys(short[] keys) {
}), KEY_UP_DELAY);
}

private boolean isMouseEmulationActive() {
return game.isMouseEmulationActive();
}

private void showMenuDialog(String title, MenuOption[] options) {
AlertDialog.Builder builder = new AlertDialog.Builder(game);
builder.setTitle(title);
Expand Down Expand Up @@ -130,6 +134,11 @@ private void showSpecialKeysMenu() {
private void showMenu() {
showMenuDialog("Game Menu", new MenuOption[]{
new MenuOption(getString(R.string.game_menu_send_keys), () -> showSpecialKeysMenu()),
new MenuOption(getString(isMouseEmulationActive() ?
R.string.game_menu_toggle_mouse_off : R.string.game_menu_toggle_mouse_on),
() -> game.toggleMouseEmulation()),
new MenuOption(getString(R.string.game_menu_toggle_keyboard),
() -> game.toggleKeyboard()),
new MenuOption(getString(R.string.game_menu_disconnect), () -> game.onBackPressed()),
new MenuOption(getString(R.string.game_menu_cancel), null),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ public boolean handleButtonUp(KeyEvent event) {
if ((context.inputMap & ControllerPacket.PLAY_FLAG) != 0 &&
event.getEventTime() - context.startDownTime > ControllerHandler.START_DOWN_TIME_MOUSE_MODE_MS &&
prefConfig.mouseEmulation) {
context.toggleMouseEmulation();
gestures.showGameMenu();
}
context.inputMap &= ~ControllerPacket.PLAY_FLAG;
break;
Expand Down Expand Up @@ -1901,10 +1901,9 @@ public void run() {
}
};

public void toggleMouseEmulation() {
public void toggleMouseEmulation(boolean enable) {
handler.removeCallbacks(mouseEmulationRunnable);
mouseEmulationActive = !mouseEmulationActive;
Toast.makeText(activityContext, "Mouse emulation is: " + (mouseEmulationActive ? "ON" : "OFF"), Toast.LENGTH_SHORT).show();
mouseEmulationActive = enable;

if (mouseEmulationActive) {
handler.postDelayed(mouseEmulationRunnable, mouseEmulationReportPeriod);
Expand Down Expand Up @@ -1986,4 +1985,27 @@ public void destroy() {
// Nothing for now
}
}

public void toggleMouseEmulation() {

boolean enable = !defaultContext.mouseEmulationActive;
defaultContext.mouseEmulationActive = enable;
defaultContext.toggleMouseEmulation(enable);

for (int i = 0; i < inputDeviceContexts.size(); i++) {
InputDeviceContext deviceContext = inputDeviceContexts.valueAt(i);
deviceContext.toggleMouseEmulation(enable);
}

for (int i = 0; i < usbDeviceContexts.size(); i++) {
UsbDeviceContext deviceContext = usbDeviceContexts.valueAt(i);
deviceContext.toggleMouseEmulation(enable);
}

Toast.makeText(activityContext, "Mouse emulation is: " + (enable ? "ON" : "OFF"), Toast.LENGTH_SHORT).show();
}

public boolean isMouseEmulationEnabled() {
return defaultContext.mouseEmulationActive;
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/limelight/ui/GameGestures.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public interface GameGestures {
void toggleKeyboard();

void showGameMenu();
}
11 changes: 7 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,16 @@
<string name="applist_details_id">App ID:</string>

<!-- In Game menu -->
<string name="game_menu_toggle_mouse_on">Enable Controller Mouse Emulation</string>
<string name="game_menu_toggle_mouse_off">Disable Controller Mouse Emulation</string>
<string name="game_menu_toggle_keyboard">Toggle On-screen Keyboard</string>
<string name="game_menu_disconnect">Disconnect</string>
<string name="game_menu_cancel">Cancel</string>
<string name="game_menu_send_keys">Send special key(s)</string>
<string name="game_menu_send_keys">Send special Key(s)</string>
<string name="game_menu_send_keys_esc">Send ESC (Menu)</string>
<string name="game_menu_send_keys_f11">Send F11 (Toggle full screen)</string>
<string name="game_menu_send_keys_ctrl_v">Send CTRL + V (Paste clipboard)</string>
<string name="game_menu_send_keys_win">Send WIN (Toggle Windows start menu)</string>
<string name="game_menu_send_keys_f11">Send F11 (Toggle Full Screen)</string>
<string name="game_menu_send_keys_ctrl_v">Send CTRL + V (Paste Clipboard)</string>
<string name="game_menu_send_keys_win">Send WIN (Toggle Windows Start Menu)</string>
<string name="game_menu_send_keys_win_d">Send WIN + D (Switch to Desktop)</string>
<string name="game_menu_send_keys_win_g">Send WIN + G (Open Xbox Game Bar)</string>
<string name="game_menu_send_keys_shift_tab">Send SHIFT + TAB (Open Steam Overlay)</string>
Expand Down

0 comments on commit c9fe96a

Please sign in to comment.