From 0653a8b5c2bf5b55088f08e46e90631ed3ba3c87 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 26 Apr 2013 00:43:14 +0200 Subject: [PATCH] Push to msg_queue when device is hotplugged. --- Makefile | 7 ++++++- input/linuxraw_joypad.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8a8c7cb8e3..2faa52b83e 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ endif ifneq ($(findstring Linux,$(OS)),) LIBS += -lrt OBJ += input/linuxraw_input.o input/linuxraw_joypad.o - JOYCONFIG_OBJ += input/linuxraw_joypad.o + JOYCONFIG_OBJ += tools/linuxraw_joypad.o endif ifeq ($(HAVE_RGUI), 1) @@ -342,6 +342,7 @@ ifeq ($(NOUNUSED_VARIABLE), yes) CFLAGS += -Wno-unused-variable endif + all: $(TARGET) config.mk config.mk: configure qb/* @@ -368,6 +369,10 @@ tools/retrolaunch/retrolaunch: $(RETROLAUNCH_OBJ) @$(if $(Q), $(shell echo echo CC $<),) $(Q)$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $< +tools/linuxraw_joypad.o: input/linuxraw_joypad.c + @$(if $(Q), $(shell echo echo CC $<),) + $(Q)$(CC) $(CFLAGS) $(DEFINES) -DNO_MSG_QUEUE -c -o $@ $< + %.o: %.S config.h config.mk $(HEADERS) @$(if $(Q), $(shell echo echo AS $<),) $(Q)$(CC) $(CFLAGS) $(ASFLAGS) $(DEFINES) -c -o $@ $< diff --git a/input/linuxraw_joypad.c b/input/linuxraw_joypad.c index a2f86ab451..388a5a4485 100644 --- a/input/linuxraw_joypad.c +++ b/input/linuxraw_joypad.c @@ -42,6 +42,10 @@ static struct linuxraw_joypad g_pads[MAX_PLAYERS]; static int g_notify; static int g_epoll; +#ifndef NO_MSG_QUEUE +static bool g_hotplug; +#endif + static void poll_pad(struct linuxraw_joypad *pad) { struct js_event event; @@ -80,7 +84,19 @@ static void linuxraw_joypad_init_pad(const char *path, struct linuxraw_joypad *p if (pad->fd >= 0) { if (ioctl(pad->fd, JSIOCGNAME(sizeof(g_settings.input.device_names[0])), pad->ident) >= 0) + { RARCH_LOG("[Joypad]: Found pad: %s on %s.\n", pad->ident, path); + +#ifndef NO_MSG_QUEUE + if (g_hotplug) + { + char msg[512]; + snprintf(msg, sizeof(msg), "Joypad #%u (%s) connected.", (unsigned)(pad - g_pads), pad->ident); + msg_queue_push(g_extern.msg_queue, msg, 0, 60); + } +#endif + } + else RARCH_ERR("[Joypad]: Didn't find ident of %s.\n", path); @@ -120,6 +136,15 @@ static void handle_plugged_pad(void) { if (g_pads[index].fd >= 0) { +#ifndef NO_MSG_QUEUE + if (g_hotplug) + { + char msg[512]; + snprintf(msg, sizeof(msg), "Joypad #%u (%s) disconnected.", index, g_pads[index].ident); + msg_queue_push(g_extern.msg_queue, msg, 0, 60); + } +#endif + RARCH_LOG("[Joypad]: Joypad %s disconnected.\n", g_pads[index].ident); close(g_pads[index].fd); memset(g_pads[index].buttons, 0, sizeof(g_pads[index].buttons)); @@ -198,6 +223,10 @@ static bool linuxraw_joypad_init(void) epoll_ctl(g_epoll, EPOLL_CTL_ADD, g_notify, &event); } +#ifndef NO_MSG_QUEUE + g_hotplug = true; +#endif + return true; } @@ -220,6 +249,10 @@ static void linuxraw_joypad_destroy(void) if (g_epoll >= 0) close(g_epoll); g_epoll = -1; + +#ifndef NO_MSG_QUEUE + g_hotplug = false; +#endif } static bool linuxraw_joypad_button(unsigned port, uint16_t joykey)