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

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

Just copy the executable to your home folder (the “username” folder) with smartftp first, then use ssh to copy it to your /etc folder with super user privileges:

$ sudo cp kodifocus /etc

I am not sure if you have to chmod it, but it doesn’t hurt either, so just do it

$ sudo chmod +x /etc/kodifocus

to be on the safe side. The extensions of files in are usually of no importance in Linux, it’s for the human. You can uninstall xdotool like this

$ sudo apt-get remove xdotool

And you can delete them old script with

$ sudo rm /etc/kodi_focus.sh

As I said, you might want to try if it really runs, since it might be that I have a different glibc version or something.If it doesn’t work I check if I can recompile it for Kodibuntu.

And yea, I noticed the same problem with the gamepad on my system, must be a Kodi thing, I will investigate further, since now I want to use my gamepad as well :smiley: The executable should work for your remote and keyboard, etc. though.

Excellent! So close! When I exit a Game everything works except the game controller! :slight_smile: You might have a different glibc. Not sure what that means. But when I install Kodibuntu I update the core right away. I believe it is on Ubuntu 14.04. Not sure what version glibc I have. Do you think it is possible to get this working? Other than the game controller it works flawless. A very smooth transition into the game and very smooth out. I am going to try some mame games now. Excellent job! cant wait to hear back. Where do you get all the information to write this stuff so quickly?

I am glad I could help. If it works it works, the glibc version doesn’t matter then.

Maybe I can find something out about the gamepad, but I think that’s how Kodi works, and I might not be able to fix this (any time soon). In case you simply disable your gamepad in Kodi settings, the script to start retroarch can be reduced to

#!/bin/bash
/usr/bin/retroarch "$@"
/etc/kodifocus

Years of sweat and tears :smiley:

Haha! Thanks! I will continue to look for something also. I could not have gotten this close with out your help. I will let you know if I find something. Thanks so much.

Hey I did run into a glitch. I don’t know if it is my fault. I went to set up my mame games using the same procedure. Without thinking, Instead of pointing to the Kodi_input.sh I pointed it to kodifocus. When I went to launch the game the screen just flashed and did nothing. My bad! But after I changed it to kodi_input.sh, it still would not launch. So I exited kodi and tested retroarch in Ubuntu. Worked fine when picking the core manualy. So I went back into kodi and noticed that after launching one platform, ex. (SNES), and then going to a MAME game the Core stays set to SNES. If I manually load the core for MAME it stays set to that. I don’t know if it has anything to do with the mistake I made. retroarch is not auto loading the corresponding cores anymore. I am going to try another fresh install.

I start retroarch by specifically naming the core to load, so I am not familiar with the reliability of core auto loading. I suggest you do the same. Just add the core to the launch options in your rom collection browser, e.g.

-L /usr/lib/libretro/snes9x_libretro.so

for snes9x. You can check what names the cores have with

$ ls /usr/lib/libretro/*.so

Sure, makes sense, I will try that when I get home. I did set it up on another machine and tested retroarch in Ubuntu successfully. Then when I launched through Kodi it would not load the core at all from the script… So retroarch can not recognize the source game through the program you wrote. I am sure it will work with -L option. :slight_smile:

As I said, I don’t know how the auto detecting of cores works, I find it highly unlikely that it has anything to do with my script, but it surely is possible.

Ohh wow! Kodi is very sensitive. So I applied the launch options as described.

 -F -L /usr/lib/libretro/snes9x_libretro.so %ROM% 

and it did absolutely nothing!. What? So I checked all the settings. Settings where good. So I deleted the entire rom collection to start from scratch. I used retroarch first to make sure it was running. Then I set it up to point to the script with the launch options. It worked perfectly. Great. So I went to install everything on my other zotac box. I tried pointing directly to retroarch first to make sure it was running ok. Then after following the same procedure and pointing to the script. I get nothing. I tried everything and checked my procedure over and over. I hope I am missing something, I can not get it to work. I checked all kodi web server setting, port is 8090, I checked and even copied the script files from the other machine. I made sure they were executable. Allow remote control is enabled. I even re-installed curl. I am thinking of trying another fresh install. I even disabled the sound. sometimes it can get caught up on sound. Is it the hardware? A fresh install might help me figure it out maybe I missed something. Ill get back.

Well I just did a fresh install for nothing. It still did not work. I went back and started over step by step. I finally got the script to work again by installing xdotool and running the original kodi_focus.sh script then switching over to kodifocus. But now I am where I was yesterday on the other machine. I can only manually change over the cores. Once I introduce

-F -L /usr/lib/libretro/snes9x_libretro.so %ROM%

It does not work for either rom collection. ???

After banging my head around for a while, I checked the first machine launch settings. Compared it to the new install and low and behold!! It was a dumb ass syntax error! I was typing

 -l /usr/lib/libretro/snes9x_libretro.so %ROM%

when I should have typed

 -L /usr/lib/libretro/snes9x_libretro.so %ROM% 

. Syntax error. The ( -L ) has to be capital! Now I will do one more fresh install to see if I had to install xdotool and run kodi_focus.sh first in order to get the kodifocus to work. I believe once I run a bad command Kodi caches it. So when I correct the bad command it still wont work. I am hoping that I do not have to install xdotool and run kodi_focus.sh first. If that’s the case, all is well and I have a sure fire procedure for any machine. I wont know until I try on a clean install. I’ll get back

[QUOTE=ufopaper;31419]I am glad I could help. If it works it works, the glibc version doesn’t matter then.

Maybe I can find something out about the gamepad, but I think that’s how Kodi works, and I might not be able to fix this (any time soon). In case you simply disable your gamepad in Kodi settings, the script to start retroarch can be reduced to

#!/bin/bash
/usr/bin/retroarch "$@"
/etc/kodifocus

Years of sweat and tears :D[/QUOTE]

Hey what can you make of this? http://forum.kodi.tv/showthread.php?tid=213040 Says its a patch?