Provide default gamepad mapping

This commit is contained in:
Iwan Timmer 2015-05-12 16:13:18 +02:00
parent 685d7731b7
commit 636559d67b
3 changed files with 82 additions and 2 deletions

View File

@ -48,3 +48,7 @@ endif()
include_directories(./moonlight-common-c ${OPUS_INCLUDE_DIRS} ${EVDEV_INCLUDE_DIRS} ${AVAHI_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS}) include_directories(./moonlight-common-c ${OPUS_INCLUDE_DIRS} ${EVDEV_INCLUDE_DIRS} ${AVAHI_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS})
target_link_libraries (moonlight PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${EVDEV_LIBRARIES} ${ALSA_LIBRARY} ${OPUS_LIBRARY} ${AVAHI_LIBRARIES} ${UDEV_LIBRARIES}) target_link_libraries (moonlight PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${EVDEV_LIBRARIES} ${ALSA_LIBRARY} ${OPUS_LIBRARY} ${AVAHI_LIBRARIES} ${UDEV_LIBRARIES})
include(${CMAKE_ROOT}/Modules/GNUInstallDirs.cmake)
install(TARGETS moonlight DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY mappings DESTINATION ${CMAKE_INSTALL_DATADIR})

View File

@ -0,0 +1,34 @@
abs_x = 0
abs_y = 1
abs_z = 2
abs_rx = 3
abs_ry = 4
abs_rz = 5
abs_deadzone = 0
abs_dpad_y = 16
abs_dpad_x = 17
reverse_x = false
reverse_y = false
reverse_rx = false
reverse_ry = false
reverse_dpad_y = false
reverse_dpad_x = false
reverse_z = false
reverse_rz = false
btn_south = 304
btn_east = 305
btn_north = 307
btn_west = 308
btn_select = 314
btn_start = 315
btn_mode = 316
btn_thumbl = 317
btn_thumbr = 318
btn_tl = 310
btn_tr = 311
btn_tl2 = 312
btn_tr2 = 313
btn_dpad_up = 544
btn_dpad_down = 545
btn_dpad_left = 546
btn_dpad_right = 547

View File

@ -29,12 +29,17 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include <getopt.h> #include <getopt.h>
#define MOONLIGHT_PATH "/moonlight/"
#define USER_PATHS ":~/.moonlight:./"
PLATFORM_CALLBACKS platform_callbacks = { PLATFORM_CALLBACKS platform_callbacks = {
.threadStart = NULL, .threadStart = NULL,
.debugPrint = NULL, .debugPrint = NULL,
@ -92,6 +97,43 @@ static void help() {
exit(0); exit(0);
} }
char* get_path(char* name) {
const char *xdg_data_dirs = getenv("XDG_DATA_DIRS");
char *data_dirs;
if (!xdg_data_dirs)
data_dirs = "/usr/share:/usr/local/share:" USER_PATHS;
else {
data_dirs = malloc(strlen(xdg_data_dirs) + strlen(USER_PATHS) + 1);
strcpy(data_dirs, xdg_data_dirs);
strcpy(data_dirs+strlen(data_dirs), USER_PATHS);
}
char *path = malloc(strlen(data_dirs)+strlen(MOONLIGHT_PATH)+strlen(name)+1);
if (path == NULL) {
fprintf(stderr, "Not enough memory\n");
exit(-1);
}
char* end;
do {
end = strstr(data_dirs, ":");
int length = end != NULL?end - data_dirs:strlen(data_dirs);
memcpy(path, data_dirs, length);
if (path[0] == '/')
sprintf(path+length, "%s%s", MOONLIGHT_PATH, name);
else
sprintf(path+length, "%s", name);
if(access(path, F_OK) != -1)
return path;
data_dirs = end + 1;
} while (end != NULL);
free(path);
return NULL;
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
STREAM_CONFIGURATION config; STREAM_CONFIGURATION config;
config.width = 1280; config.width = 1280;
@ -121,7 +163,7 @@ int main(int argc, char* argv[]) {
char* app = "Steam"; char* app = "Steam";
char* action = NULL; char* action = NULL;
char* address = NULL; char* address = NULL;
char* mapping = NULL; char* mapping = get_path("mappings/default.conf");
int option_index = 0; int option_index = 0;
bool sops = true; bool sops = true;
bool localaudio = false; bool localaudio = false;
@ -161,7 +203,7 @@ int main(int argc, char* argv[]) {
input_create(optarg, mapping); input_create(optarg, mapping);
break; break;
case 'k': case 'k':
mapping = optarg; mapping = get_path(optarg);
break; break;
case 'l': case 'l':
sops = false; sops = false;