Skip to content

SDL3 upgrade #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
java-version: 17
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Android
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
java-version: 17
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Android
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
java-version: 17
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Android
Expand Down
18 changes: 18 additions & 0 deletions LICENSE_hartmann
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Jamepad
Copyright (C) 2016 William Hartman

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ You can get help on the [libgdx discord](https://discord.gg/6pgDK9F).
## License

The project is licensed under the Apache 2 License, meaning you can use it free of charge, without strings attached in commercial and non-commercial projects. We love to get (non-mandatory) credit in case you release a game or app using this project!
Some code in the `desktop` project is forked and modified from the original work by [William Hartman](https://github.com/williamahartman/Jamepad). These classes retained author notice.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath "org.docstr:gwt-gradle-plugin:1.1.29"
classpath "com.android.tools.build:gradle:7.2.2"
classpath "com.android.tools.build:gradle:8.7.3"
}
}

Expand All @@ -18,9 +18,9 @@ allprojects {
ext {

appName = 'gdx-controllers'
gdxVersion = '1.9.11'
roboVMVersion = '2.3.19'
jamepadVersion = '2.26.5.0'
gdxVersion = '1.13.1'
roboVMVersion = '2.3.23'
lwjgl3Version = '3.4.0-SNAPSHOT'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the snapshot version needed? Not good to have this library point to a snapshot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment yes, so I would only merge this after a stable lwjgl3 release exists.


isReleaseBuild = {
return project.hasProperty("RELEASE")
Expand Down
3 changes: 1 addition & 2 deletions gdx-controllers-android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.badlogicgames.gdx.controllers">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application/>
</manifest>
8 changes: 4 additions & 4 deletions gdx-controllers-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'com.android.library'
project.group = 'com.badlogicgames.gdx-controllers'

android {

compileSdkVersion 29
namespace "com.badlogic.gdx.controllers"
compileSdk 35

defaultConfig {
minSdkVersion 16
targetSdkVersion 29
minSdkVersion 21
targetSdkVersion 35
}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public boolean onKey (View view, int keyCode, KeyEvent keyEvent) {
event.code = keyCode;
eventQueue.add(event);
}
return keyCode != KeyEvent.KEYCODE_BACK || Gdx.input.isCatchBackKey();
return keyCode != KeyEvent.KEYCODE_BACK || Gdx.input.isCatchKey(keyCode);
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion gdx-controllers-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ eclipse {
}

dependencies {
implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx:$gdxVersion"
}

targetCompatibility = 1.7
Expand Down
16 changes: 11 additions & 5 deletions gdx-controllers-desktop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ tasks.getByName('processResources') {
dependencies {
api project(":gdx-controllers-core")
implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
api("com.badlogicgames.jamepad:jamepad:$jamepadVersion") {
exclude group: 'com.badlogicgames.gdx', module: 'gdx-jnigen-loader'
}
implementation "org.lwjgl:lwjgl-sdl:$lwjgl3Version"
implementation "org.lwjgl:lwjgl-sdl:$lwjgl3Version:natives-linux"
implementation "org.lwjgl:lwjgl-sdl:$lwjgl3Version:natives-linux-arm32"
implementation "org.lwjgl:lwjgl-sdl:$lwjgl3Version:natives-linux-arm64"
implementation "org.lwjgl:lwjgl-sdl:$lwjgl3Version:natives-linux-riscv64"
implementation "org.lwjgl:lwjgl-sdl:$lwjgl3Version:natives-macos"
implementation "org.lwjgl:lwjgl-sdl:$lwjgl3Version:natives-macos-arm64"
implementation "org.lwjgl:lwjgl-sdl:$lwjgl3Version:natives-windows"
implementation "org.lwjgl:lwjgl-sdl:$lwjgl3Version:natives-windows-x86"
}

targetCompatibility = 1.7
sourceCompatibility = 1.7
targetCompatibility = 1.8
sourceCompatibility = 1.8


ext {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.badlogic.gdx.controllers.desktop;

import com.badlogic.gdx.controllers.ControllerManager;

/**
* Class defining the configuration of a {@link ControllerManager}.
*
* @author Benjamin Schulte
*/
public class Configuration {
/**
* The max number of controllers the ControllerManager should deal with
*/
public int maxNumControllers = 4;

/**
* Use RawInput implementation instead of XInput on Windows, if applicable. Enable this if you
* need to use more than four XInput controllers at once. Comes with drawbacks.
*/
public boolean useRawInput = false;

/**
* Disable this to return to legacy temporary file loading of database file.
*/
public boolean loadDatabaseInMemory = true;
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
import com.badlogic.gdx.controllers.desktop.support.CompositeControllerListener;
import com.badlogic.gdx.controllers.desktop.support.JamepadControllerMonitor;
import com.badlogic.gdx.controllers.desktop.support.JamepadShutdownHook;
import com.badlogic.gdx.controllers.desktop.support.SDLControllerManager;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;

import java.io.IOException;

public class JamepadControllerManager extends AbstractControllerManager implements Disposable {
// assign a Jamepad configuration to this field at game startup to override defaults
public static com.studiohartman.jamepad.Configuration jamepadConfiguration;
public static Configuration jamepadConfiguration;

private static boolean nativeLibInitialized = false;
private static com.studiohartman.jamepad.ControllerManager controllerManager;
private static SDLControllerManager controllerManager;

private final CompositeControllerListener compositeListener = new CompositeControllerListener();

Expand All @@ -26,10 +27,10 @@ public JamepadControllerManager() {

if (!nativeLibInitialized) {
if (jamepadConfiguration == null) {
jamepadConfiguration = new com.studiohartman.jamepad.Configuration();
jamepadConfiguration = new Configuration();
}

controllerManager = new com.studiohartman.jamepad.ControllerManager(jamepadConfiguration);
controllerManager = new SDLControllerManager(jamepadConfiguration);
controllerManager.initSDLGamepad();

JamepadControllerMonitor monitor = new JamepadControllerMonitor(controllerManager, compositeListener);
Expand Down Expand Up @@ -70,7 +71,7 @@ public void dispose() {
}

/**
* @see com.studiohartman.jamepad.ControllerManager#addMappingsFromFile(String)
* @see SDLControllerManager#addMappingsFromFile(String)
*/
public static void addMappingsFromFile(String path) throws IOException, IllegalStateException {
controllerManager.addMappingsFromFile(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.badlogic.gdx.controllers.desktop.support;

import org.lwjgl.sdl.SDLGamepad;

/**
* The list of axes available on a gamepad
*
* Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to
* SDL_JOYSTICK_AXIS_MAX, and are centered within ~8000 of zero, though
* advanced UI will allow users to set or autodetect the dead zone, which
* varies between gamepads.
*
* Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX (fully
* pressed) when reported by SDL_GetGamepadAxis(). Note that this is not the
* same range that will be reported by the lower-level SDL_GetJoystickAxis().
*/
public enum ControllerAxis {
INVALID(SDLGamepad.SDL_GAMEPAD_AXIS_INVALID),
LEFTX(SDLGamepad.SDL_GAMEPAD_AXIS_LEFTX),
LEFTY(SDLGamepad.SDL_GAMEPAD_AXIS_LEFTY),
RIGHTX(SDLGamepad.SDL_GAMEPAD_AXIS_RIGHTX),
RIGHTY(SDLGamepad.SDL_GAMEPAD_AXIS_RIGHTY),
LEFT_TRIGGER(SDLGamepad.SDL_GAMEPAD_AXIS_LEFT_TRIGGER),
RIGHT_TRIGGER(SDLGamepad.SDL_GAMEPAD_AXIS_RIGHT_TRIGGER),;

public static final ControllerAxis[] VALUES = values();

private final int id;

ControllerAxis(int id) {
this.id = id;
}

public int getId() {
return id;
}

public static ControllerAxis getById(int id) {
for (ControllerAxis axis : VALUES) {
if (axis.id == id)
return axis;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.badlogic.gdx.controllers.desktop.support;

import org.lwjgl.sdl.SDLGamepad;

/**
* The list of buttons available on a gamepad
*
* For controllers that use a diamond pattern for the face buttons, the
* south/east/west/north buttons below correspond to the locations in the
* diamond pattern. For Xbox controllers, this would be A/B/X/Y, for Nintendo
* Switch controllers, this would be B/A/Y/X, for GameCube controllers this
* would be A/X/B/Y, for PlayStation controllers this would be
* Cross/Circle/Square/Triangle.
*
* For controllers that don't use a diamond pattern for the face buttons, the
* south/east/west/north buttons indicate the buttons labeled A, B, C, D, or
* 1, 2, 3, 4, or for controllers that aren't labeled, they are the primary,
* secondary, etc. buttons.
*
* The activate action is often the south button and the cancel action is
* often the east button, but in some regions this is reversed, so your game
* should allow remapping actions based on user preferences.
*
* You can query the labels for the face buttons using
* SDL_GetGamepadButtonLabel()
* */
public enum ControllerButton {

INVALID(SDLGamepad.SDL_GAMEPAD_BUTTON_INVALID),
SOUTH(SDLGamepad.SDL_GAMEPAD_BUTTON_SOUTH), /** Bottom face button (e.g. Xbox A button) */
EAST(SDLGamepad.SDL_GAMEPAD_BUTTON_EAST), /** Right face button (e.g. Xbox B button) */
WEST(SDLGamepad.SDL_GAMEPAD_BUTTON_WEST), /** Left face button (e.g. Xbox X button) */
NORTH(SDLGamepad.SDL_GAMEPAD_BUTTON_NORTH), /** Top face button (e.g. Xbox Y button) */
BACK(SDLGamepad.SDL_GAMEPAD_BUTTON_BACK),
GUIDE(SDLGamepad.SDL_GAMEPAD_BUTTON_GUIDE),
START(SDLGamepad.SDL_GAMEPAD_BUTTON_START),
LEFT_STICK(SDLGamepad.SDL_GAMEPAD_BUTTON_LEFT_STICK),
RIGHT_STICK(SDLGamepad.SDL_GAMEPAD_BUTTON_RIGHT_STICK),
LEFT_SHOULDER(SDLGamepad.SDL_GAMEPAD_BUTTON_LEFT_SHOULDER),
RIGHT_SHOULDER(SDLGamepad.SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER),
DPAD_UP(SDLGamepad.SDL_GAMEPAD_BUTTON_DPAD_UP),
DPAD_DOWN(SDLGamepad.SDL_GAMEPAD_BUTTON_DPAD_DOWN),
DPAD_LEFT(SDLGamepad.SDL_GAMEPAD_BUTTON_DPAD_LEFT),
DPAD_RIGHT(SDLGamepad.SDL_GAMEPAD_BUTTON_DPAD_RIGHT),
MISC1(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC1), /** Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button, Google Stadia capture button) */
RIGHT_PADDLE1(SDLGamepad.SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1), /** Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1) */
LEFT_PADDLE1(SDLGamepad.SDL_GAMEPAD_BUTTON_LEFT_PADDLE1), /** Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3) */
RIGHT_PADDLE2(SDLGamepad.SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2), /** Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2) */
LEFT_PADDLE2(SDLGamepad.SDL_GAMEPAD_BUTTON_LEFT_PADDLE2), /** Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4) */
TOUCHPAD(SDLGamepad.SDL_GAMEPAD_BUTTON_TOUCHPAD), /** PS4/PS5 touchpad button */
MISC2(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC2), /** Additional button */
MISC3(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC3), /** Additional button */
MISC4(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC4), /** Additional button */
MISC5(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC5), /** Additional button */
MISC6(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC6),; /** Additional button */

public static final ControllerButton[] VALUES = values();

private final int id;

ControllerButton(int id) {
this.id = id;
}

public int getId() {
return id;
}

public static ControllerButton getById(int id) {
for (ControllerButton button : VALUES) {
if (button.id == id)
return button;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.badlogic.gdx.controllers.desktop.support;

import org.lwjgl.sdl.SDLGamepad;

/**
* The set of gamepad button labels
*
* This isn't a complete set, just the face buttons to make it easy to show
* button prompts.
*
* For a complete set, you should look at the button and gamepad type and have
* a set of symbols that work well with your art style.
*/
public enum ControllerButtonLabel {
UNKNOWN(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN),
A(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_A),
B(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_B),
X(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_X),
Y(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_Y),
CROSS(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_CROSS),
CIRCLE(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_CIRCLE),
SQUARE(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_SQUARE),
TRIANGLE(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE),;

public static final ControllerButtonLabel[] VALUES = values();

private final int id;

ControllerButtonLabel(int id) {
this.id = id;
}

public int getId() {
return id;
}

public static ControllerButtonLabel getById(int id) {
for (ControllerButtonLabel label : VALUES) {
if (label.id == id)
return label;
}

return null;
}
}
Loading