I would like to use a script to find out the username - of the user who is currently on the physical console (who has command of the keyboard, mouse and graphical display)?
I do not just want to know who runs X (as the current console can be switched to another terminal and another user).
who etc. show who is logged at which terminal. This is simple. I would like to know, however, who owns currently the physical console (display, keyboard etc.). For example, if two users run displays :0 and :1, and I can switch between the displays with ctrl+alt+7 and ctrl+alt+8, I would like to know which user currently has the connection between his or her display and the actual, physical screen.
One more clarification:
I am not interested in knowing my own username. I have a script, running as another user or root, that needs to know who uses the physical display. There can be several X sessions running by different users, some of them virtualized, some of them connected to a remote X server, but I am only interested in the one that is actually displaying output on the monitor.
Yet another clarification:
Whatever the command is, the output must be different after pressing Ctrl+Alt+F1 (switching to another virtual console).