0

I'm currently developing a Kiosk style application that will run on a Raspberry Pi 3B+ where my frontend is a Chromium instance running in Kiosk mode and my backend is a locally hosted ASP.NET Core 3.0 project. My problem now is that the user needs to enter some text to search for something but I only have the touchscreen interface, no keyboard. So now I need to focus the XVKBD instance running in the background, I can do this by using wmctrl to focus it. This works perfectly fine when running the command from a terminal, but doesn't work when my ASP.NET application is invoking it with a Process, here is my code:

Bash to focus XVKBD/ Chromium:

# Show XVKBD
wmctrl -a xvkbd

# Show Chromium
wmctrl -a Chromium

C# Code

public void FocusKeyboard()
{
    var proc = new Process
    {
        StartInfo = new ProcessStartInfo("bash", "\"wmctrl -a xvkbd\"")
    };

    proc.Start();
}

///<param name="title">Passed in from JS to tell wmctrl what to focus</param>
public void FocusChromium(string title)
{
    var proc = new Process
    {
        StartInfo = new ProcessStartInfo("bash", $"\"wmctrl -a {title}\"")
    };

    proc.Start();
}

Note that the C# code is being called by JavaScript running in the frontend via SignalR

Expected behaviour: When I call the FocusKeyboard method it should focus the xvkbd instance and when I call the FocusChromium method it should focus the Chromium instance.

Actual behaviour: It does nothing.

So my question is this: How can I switch focus for my user in a ASP.NET application?

MindSwipe
  • 7,193
  • 24
  • 47
  • your web server is not running with a handle on your xserver. in fact you don't need to be logged on at all and could access the server remotely without having a running session on your raspberry. calling a graphical application is not going to open it on your desktop, and any application your webserver starts will run as the webserver-user, which usually is fairly restricted, but at the same time has access to all the webserver files. i'd look for a different solution, perhaps a javascript keyboard you have on your webpage. otherwise you may want to ask over at https://unix.stackexchange.com/ – FalcoGer Jul 29 '19 at 09:24
  • It seems I missunderstood. is any c# code actually being executed? what happens when you execute that c# code via console instead of calling it by javascript? – FalcoGer Jul 29 '19 at 09:27
  • When running the C# code from a console it works flawlessly. Also yes, the C# code is being executed on the server – MindSwipe Jul 29 '19 at 09:28
  • so the parent process of that code is chrome/chrome's js interpreter and the user of the c# process is also the logged in user on your x session? – FalcoGer Jul 29 '19 at 09:30
  • The Javascript running in chromium is calling an exposed SignalR hub via a WebSocket, that SignalR Hub (owned and instantiated by the ASP.NET application) is the running the C# code. So the parent of the JS is Chrome but the parent of the C# is the ASP.NET process that was run manually by me in a terminal – MindSwipe Jul 29 '19 at 09:34
  • we must differenciate here. the webserver and the client may be on the same machine, but for linux they're in different worlds, running as different users. one is headless, the other uses the x session. and one user can't control another user's x session, changing focus, opening windows, etc. – FalcoGer Jul 29 '19 at 09:35
  • so you run the asp web server from an (x-) terminal with user rights. the code executes, and nothing happens. but when you execute the same code from a standalone c# program from the same terminal, it works? – FalcoGer Jul 29 '19 at 09:37
  • have you had a look at this? https://chrome.google.com/webstore/detail/touch-kiosk-keyboard/lfaiipcbbikbnfcgcmaldlacamgekmnb?hl=en it seems like an easier solution than to fiddle with linux. This seems relevant, though no answer yet: https://stackoverflow.com/questions/39159799/virtual-keyboard-for-chromium-in-kiosk-mode-fullscreen – FalcoGer Jul 29 '19 at 09:41
  • Yes, exactly. When the web server that is run from a x-terminal runs the code nothing happens (although the wmctrl command gets executed, I can see its PID) and when the same code is run from a standalone C# console app it works. Also, thanks for the link, I'll check it out after lunch – MindSwipe Jul 29 '19 at 09:42
  • what's the output of the wmctrl call? you can check stdout/err with something like this: https://pastebin.com/aUz6SNhX this is a sample of code i used for measuring temperature by calling vcgencmd on the pi, though I use a different method now, it's still a good example at how to fetch a program's output. maybe you get some useful error message or something from this. – FalcoGer Jul 29 '19 at 11:10
  • Did you solve your issue? – FalcoGer Jul 30 '19 at 11:39
  • Ah yes I did, sorry for not answering. I was just ecstatic that it worked and ashamed that I didn't think of it. The Touch Kiosk extension works flawlessly – MindSwipe Jul 30 '19 at 11:47

1 Answers1

1

Instead of trying to fiddle around with linux and the x-session from your web server, you could look into an extention to chrome that gives you a virtual keyboard, such as for example this one. In addition to bypassing all that trouble, and it being easier, it also prevents the user from having access to the system keyboard, which they might potentially use to break out of your browser's kiosk mode.

FalcoGer
  • 2,278
  • 1
  • 12
  • 34