Game Controller inputs running in the backgroud of Kodi after launching retrorch

I am having serious trouble over figuring out how to prevent KODI from receiving signals from my game controllers after launching snes roms through Rom collection browser or advanced launcher. I am strictly using retroarch 1.2.2 for my emulator. The game controller is reeking havoc in the background after playing a game. It is simply a mess when exiting retroarch. I painfully have everything working after weeks of researching. This seems to be the last issue (hopefully) almost a week of searching and I am at the end of my wits. I am not a Linux expert. I am running Kodibuntu with rom collection browser, and retroarch. I just want to be able to launch a snes game, use my game controller with out the inputs running in the background, and I want to be where I was when I exit the game. Can anyone please give me an Idea How I can do this, or direct me in the right area? I do not wish to kill kodi, but if I have to, so be it. Thank you so much in advance for any help.

P.S. I am Running Kodi Isengard 15.2 on a Zotac Zbox ID81 plus. the games launch , play and exit perfectly. With good sound.

You have two options: 1.) disable the gamepad input in Kodi’s settings permanently. However then you wont be able to use your gamepad to maneuver around in Kodi at all.

2.) Write a script that disables the gamepad in Kodi, then starts retroarch, and after retroarch quits, enable it again, something like:


#!/bin/bash

disable_gamepad_in_kodi
retroarch $@
enable_gamepad_in_kodi

and then call this script instead of retroarch in your advanced launcher or rombrowser.

To enable and disable the gamepad in Kodi have a look here: http://kodi.wiki/view/JSON-RPC_API/v6

If I find the time I might write the script myself, since I have the same “problem”, however I opted for option 1.) since I don’t really need my gamepad in Kodi, might be nice though. I did the same with my screensaver before, since otherwise Kodi would turn my screen off while playing games.

Maybe an alternative would be to use xdotool ( http://www.semicomplete.com/projects/xdotool/ it’s available in most Linux distros ) or similar to remove the input focus from Kodi, but I am not sure if this works.

[Edit] Well, I wrote the script, you can find it here: http://pastebin.com/cmWYFiFQ You’ll need curl for that, and you need to have to enable in Kodi that it can be controlled remotely. The function “getsettingvalue” is of no interest to you, but I use it for my display turn off timer.

[QUOTE=ufopaper;31332]You have two options: 1.) disable the gamepad input in Kodi’s settings permanently. However then you wont be able to use your gamepad to maneuver around in Kodi at all.

2.) Write a script that disables the gamepad in Kodi, then starts retroarch, and after retroarch quits, enable it again, something like:


#!/bin/bash

disable_gamepad_in_kodi
retroarch $@
enable_gamepad_in_kodi

and then call this script instead of retroarch in your advanced launcher or rombrowser.

To enable and disable the gamepad in Kodi have a look here: http://kodi.wiki/view/JSON-RPC_API/v6

If I find the time I might write the script myself, since I have the same “problem”, however I opted for option 1.) since I don’t really need my gamepad in Kodi, might be nice though. I did the same with my screensaver before, since otherwise Kodi would turn my screen off while playing games.

Maybe an alternative would be to use xdotool ( http://www.semicomplete.com/projects/xdotool/ it’s available in most Linux distros ) or similar to remove the input focus from Kodi, but I am not sure if this works.

[Edit] Well, I wrote the script, you can find it here: http://pastebin.com/cmWYFiFQ You’ll need curl for that, and you need to have to enable in Kodi that it can be controlled remotely. The function “getsettingvalue” is of no interest to you, but I use it for my display turn off timer.[/QUOTE]

Excellent! I really appreciate your help. I would like to either disable the game controller in kodi or Use your script, but since I am not all that familiar with Linux other than basic commands and editing config files through ssh terminal, I am completely lost on how to create or apply any of the options you have presented me. Not familiar with curl. What type of file do I create for the script? .cfg? and where do I put it? how do I call it? Which ever is easier, I would need a step by step. I will look through the links you gave me and try to figure it out, but any additional help would be appreciated. Thanks again!

Ok, I downloaded the toggle_kodi_settings.sh script. Please excuse my inexperience. Now I will try to figure out what you meant about needing curl. Does it matter where you place the script? Enabling Kodi to be controlled remotely is not a problem. Thanks

Ok this is what I got for curl. curl is “A command line tool for getting or sending files using (https://en.wikipedia.org/wiki/URL) syntax.” If that is the case, when rom collection browser asks me for the path to the emulator. Where do I point it and how do I apply curl?

I am also completely lost about enabling or disabling the controller.

Howdy,

it does not matter where you place the script, as long as you tell advanced launcher or rombrowser where it is. Just replace the retroarch command in these launchers with the path to the script. And make it executable first

$ chmod +x path_to_script

Curl is a program in Linux [1], you most likely have it already, so you should just try it out, I am more than sure it will work out of the box. In the script, there is variable called “address” you need to input the correct address for your Kodi setup, usually just change the port to what Kodi listens to, i.e. change the 8090 to whatever you can see in your Kodi settings (Settings Menu: “Kodi” -> “Web Server” -> “Allow Remote Control via HTTP” and check for the port). Last but not least make sure retroarch is actually in /usr/bin, you can check with

$ which retroarch

If it is not, just change the path in the script to the correct one.

I am glad I can help.

1: https://wiki.ubuntuusers.de/curl

Ok, Let me get this straight. If I were to do this step by step:

  1. Place the “toggle_kodi_settings.sh” script anywhere, ex.into my “etc” folder.

  2. make it executable:

 $ chmod +x /etc/toggle_kodi_settings.sh

3.Check Kodi Web server setting and make sure the “allow remote control via HTTP” setting is set to listen to port 8090

  1. set up Rom Collection Browser to point to “/etc/toggle_kodi_settings.sh” instead of “/usr/bin/retroarch”

I can not test it out now. I can check it when I get home. Assuming all my syntax is correct and yes, that is the correct path to my retroarch, Would this be all I need to do?

Would I need to edit the script?

I am also assuming curl is installed, but once it is installed or already there, the script does the rest, Correct?

Yes that’s right (except for the white space in your chmod command after /etc, but I guess it’s just typo)

You might want to rename the script, depending on how you feel about it; you can do it with

$ mv toggle_kodi_settings.sh whatever(.sh)

Excellent! yes it was a typo! Thanks! Can I rename it in windows and copy it over via smb?

Yes, sure.

Good luck, let’s see if it works as intended.

Excellent I wont be home for another 5 hrs I will get back with the results. Thanks again

Ok, I got the script to run. It seemed to work but when exiting a game, all controls are lost except some mouse functions. Had to re-boot. I did notice while in KODI 15.2 settings, there is an input setting option to disable game controller joystick input. What?? Why didn’t I see this before? So I decided to set up everything on a fresh install without the script and just disable the input for the game controller in settings. I set up RCB to point to retroarch. Navigated with my remote to launch a game. Game launched fine and the game controller worked fine. Then when exiting the game, lo and behold! Exact same result as when using the script!! All inputs stop working including my remote. Even without launching a game, once the game controller is disabled and then re-enabled again, it will not function until I restart Kodi. While I was researching I did come across someone else having the same problem, I think there is a kill kodi in background and then restart on exit script. I found this: http://libretro.com/forums/showthread.php?t=3684 I couldn’t make heads or tails if it would work for Ubuntu. Can your script work or should I try to kill Kodi in back ground? thanks for all your support.

There is no problem running this on top of windows. It is so easy to set up. I used launch box and big box inside Kodi. Just Works, no tinkering! But I do not prefer to run on top of windows and all its overhead. there has got to be a way for this to work.

That is because Kodi doesn’t grab back the input focus when retroarch quits. This is actually the reason why I wrote the script in the first place, and I was wondering why it was working for you :smiley: Because it is curious that the gamepad would still work while you run retroarch, but not afterwards. Anywho, you need to install xdotool:

$ sudo apt-get install xdotool

will do. Then I wrote a script like this

#!/usr/bin/xdotool
search --sync kodi
windowfocus --sync %1

You have to make this script executable as well (chmod +x …), and call it in the last line of your retroarch_gampead_thingy script.

Assuming you call this new script “kodi_focus” and place it in /etc you would have to add the line

/etc/kodi_focus

to the end of the script with the gamepad stuff. Then it should work, at least it does for me :smiley:

[Edit] Oh an alternative would be to use a window manager, like fluxbox or openbox, but I think xdotool is the better solution, given that you already have your gamepad script. Kodus to you that you stick with Linux, I know it can be a hassle, but for me at least as long as I have time to spare it is actually fun to tinker with it.

And did the Gamepad thing work, did it stop moving the cursor around? Becuase it could be that you need another option enabled as well: “Kodi” -> “Services” -> “Remote Control” -> “Allow local programs to remotely control Kodi” (or something)

(And btw, this is all not retroarch specific, in case you try a different emulator or any other program, it is Kodi related, since it is Kodi what doesn’t recognize that an external app is running, so you could replace the line with retroarch in your script with any other executable.)

Thank you , I do have “allow local programs to remotely control kodi” enabled. I followed your instructions for kodi_focus, Via:

$ sudo nano /etc/kodi_focus.sh 

copy and paste your script. but I am getting the same results. Sometimes the screen stays in a small windowed mode. I named it kodi_focus.sh. I am assuming it is a .sh extention. I also named the original script kodi_input.sh. Both are in the /etc/ directory. I made them both executable with:

$ sudo chmod +x /etc/kodi_focus.sh

I added the line " /etc/kodi_focus " to the end of “kodi_input.sh” script. I even tried “/etc/kodi_focus.sh”. But it is still the same results. Am I missing something?

I did notice under RCB configuration, launch games, there is options to set a “pre launch CMD” and “post launch CMD”. Everything is working the way it should Just need to get controls back on exit. I have read so many posts where people just seem to set everything up and do not mention any issues. I have got the same results on 2 different machines. Why is this rarely mentioned? RCB and retroarch have been around for a while I would have figured there would be a surefire way to simply fix this.

So you did install xdotool? I think the problem is that you actually do need a Window Manager for xdotool to work, I myself use Ratpoison [1] + xdotool And I guess that most people use a more heavy weight window manager like Openbox, Fluxbox, etc., then there shouldn’t be a problem with the input.

So if you want to give it a try look out for a file called .xinitrc in your home folder, and have a look at it. It might be that Kodibuntu uses systemd to start Kodi, I am not sure, then there wouldn’t be an .xinitrc can you check and report back whats in it?

1: http://www.nongnu.org/ratpoison/

I do not see a .xinitrc file. I have a home folder and then my “username” folder. Did not see it. I did install xdotool. What do I do with the “ratpoison-1.4.8.tar” file I downloaded?

Yea I meant the “username folder”, that is the homer folder of said user. And you can install ratpoison with

sudo apt-get install ratpoison

you don’t need the tar file.

In any case, you “simply” need to start ratpoison with Kodi. I think, but I am not 100% sure, that Kodibuntu uses lightdm. So this is what we can try, post the output of

$ grep Exec /usr/share/xsession/*

If there is nothing with “Kodi” in it, then I am at a loss, you would have to ask the folks of Kodibuntu on their forums then.

Edit: another alternative might be, that I am writing a little program which can switch input focus back to Kodi without a WM, since then I can get rid of ratpoison (and xdotool) as well, I have to investigate.

Ok, I did it, it works for me at least.

Here is the program

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <X11/X.h>
#include <X11/Xlib.h>

#define WNDNAME "Kodi"

void
die(char *s)
{
  fprintf(stderr, "%s
", s);
  exit(1);
}

int
main(int argc, char *argv[])
{
  Display *dpy;
  Window w, p, *c;
  char *nam;
  int i, n;
  int stat;

  dpy = XOpenDisplay(NULL);
  if(dpy == NULL)
    die("xopendisplay");
  n = 0;
  stat = XQueryTree(dpy, XDefaultRootWindow(dpy), &w, &p, &c, &n);
  if(stat == 0)
    die("xquerytree");
  for(i = 0; i < n; i++){
    XFetchName(dpy, c[i], &nam);
    if(nam){
      if(!strcmp(WNDNAME, nam)){
        XSetInputFocus(dpy, c[i], RevertToParent, CurrentTime);
	XGrabKeyboard(dpy, c[i], True, GrabModeAsync, GrabModeAsync, CurrentTime);
	exit(0);
      }
      XFree(nam);
    }
  }
  XFree(c);
  XCloseDisplay(dpy);
  exit(1);
}

save it as kodifocus.c

you can compile it with

$ gcc -o kodifocus kodifocus.c -lX11

This will result in an executable called kodifocus, you can uninstall xdotool now, and replace the script I provided (kodi_focus.sh) with the newly created executable. Then change the line in the gamepad script which pointed to the old script to the new executable.

If you trust me :wink: and don’t want to bother with compiling the code yourself you can download the executable (it’s 64bit, but so is Kodibuntu) from here: http://s000.tinyupload.com/index.php?file_id=92658168894197845850 If you use this executable, then you can check if it even runs on your system in your ssh, just call it like (maybe you need another chmod +x …)

$ /etc/kodifocus

if nothing happens (no complaints from your system) then it should work :smiley:

If everything works, you don’t need xdotool nor ratpoison.

Great! I cant wait to try it. So much appreciated! I have been experimenting. It seems like an argument with the usb connections. I have a logitec F710 wireless game controller and a wired XBOX 360 controller. I also have a Logitec K830 Wireless keyboard with mouse pad and a wired usb keyboard. When running your original script as intended, after exiting a game: I am able to re-gain control of either game controller simply from re-connecting the usb connection. I can not re-gain control of either keyboard by doing the same. But I do still have mousepad functions. ?hmmmm?

Anywho, Second choice looks great! I did not install ratpoison. How do I uninstall xdotool? Not familiar with compiling! How do I get permission to put your “kodifocus” in etc foder? I usually create the script using “sudo nano” to get it there, but permission is denied when I try to move a file there. I am moving it there from windows Via smartftp.

There is no extension to the Kodifocus file? Do I have to make it executable via chmod +x?

I am assuming all I have to do is place this file in my etc directory, and call on it through the script and that’s it? Sorry do many questions, Thank you