View previous topic :: View next topic |
Author |
Message |
Holysword l33t
Joined: 19 Nov 2006 Posts: 946 Location: Greece
|
Posted: Mon Nov 07, 2016 10:03 pm Post subject: [UNSOVABLE] Screenshoting Another X Display |
|
|
Is there any way to get a screenshot of another X server instance, running at another $DISPLAY?
If I try:
import -window root -display :2.0 ./test.png
I get just a black image. _________________ "Nolite arbitrari quia venerim mittere pacem in terram non veni pacem mittere sed gladium" (Yeshua Ha Mashiach)
Last edited by Holysword on Thu Nov 10, 2016 8:30 am; edited 1 time in total |
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9678 Location: almost Mile High in the USA
|
Posted: Tue Nov 08, 2016 12:00 am Post subject: |
|
|
Yes it should work just fine, anything that has proper -display (DISPLAY=) handling theoretically should work.
However I've had problems with applications that use Xvideo that sends video data straight to the screen bypassing the normal X video buffer.
And also had problems with screensaver kick-in... _________________ Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching? |
|
Back to top |
|
|
Roman_Gruber Advocate
Joined: 03 Oct 2006 Posts: 3846 Location: Austro Bavaria
|
Posted: Tue Nov 08, 2016 12:26 pm Post subject: |
|
|
I think it depends on your window manager
I'm kinda certain that scrot works in i3wm on any attached screen with my custom key binding. |
|
Back to top |
|
|
Holysword l33t
Joined: 19 Nov 2006 Posts: 946 Location: Greece
|
Posted: Tue Nov 08, 2016 2:36 pm Post subject: |
|
|
scrot also doesn't work here. Maybe my problem is not really clear.
Imagine I have two X sessions started (I've tried with Enlightenment and KDE), one at display :1.0 and another at display :2.0
In display :1.0, I open a terminal and type "sleep 5 && scrot test.png". Then I quickly switch to display :2.0 by pressing ALT+CTRL+F2 and wait. Once I look at test.png, it is completely black.
I am imagining that X stops rendering the screen at :1.0 as soon as I switch to another session, because supposedly it is not needed... is that correct? _________________ "Nolite arbitrari quia venerim mittere pacem in terram non veni pacem mittere sed gladium" (Yeshua Ha Mashiach) |
|
Back to top |
|
|
Roman_Gruber Advocate
Joined: 03 Oct 2006 Posts: 3846 Location: Austro Bavaria
|
Posted: Tue Nov 08, 2016 2:54 pm Post subject: |
|
|
I think it depends on how you have set it up your box, your environment
I'm not sure what your gpu driver or the x-server does.
You may be correct that the gpu driver or the x-server stops rendering that second "inactive" x session.
Here we are back to the question, how you have set it up. And whats the impact on that configuration. |
|
Back to top |
|
|
Holysword l33t
Joined: 19 Nov 2006 Posts: 946 Location: Greece
|
Posted: Tue Nov 08, 2016 3:09 pm Post subject: |
|
|
Roman_Gruber wrote: | I think it depends on how you have set it up your box, your environment
I'm not sure what your gpu driver or the x-server does.
You may be correct that the gpu driver or the x-server stops rendering that second "inactive" x session.
Here we are back to the question, how you have set it up. And whats the impact on that configuration. |
My sessions are started from the TTY with a "startx" call. My .xinitrc file looks like this:
Code: | xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
export DE=kde
export XDG_CURRENT_DESKTOP=kde
exec enlightenment_start
|
I don't remember what the xrandr thing is doing, but it has something to do with my optimus GPU thing.
EDIT#1: just tested in Kubuntu default environment without the xrandr or optimus shenanigans, got black screen also. _________________ "Nolite arbitrari quia venerim mittere pacem in terram non veni pacem mittere sed gladium" (Yeshua Ha Mashiach) |
|
Back to top |
|
|
dufeu l33t
Joined: 30 Aug 2002 Posts: 924 Location: US-FL-EST
|
Posted: Wed Nov 09, 2016 11:04 pm Post subject: |
|
|
Holysword wrote: | In display :1.0, I open a terminal and type "sleep 5 && scrot test.png". Then I quickly switch to display :2.0 by pressing ALT+CTRL+F2 and wait. Once I look at test.png, it is completely black.
I am imagining that X stops rendering the screen at :1.0 as soon as I switch to another session, because supposedly it is not needed... is that correct? |
When you perform an ALT+CTL+F(n), X automatically suspends the current AIGLX client: Code: | [176195.789] (II) AIGLX: Suspending AIGLX clients for VT switch |
Therefore you will always get a black screen.
Basically, X is managing window buffers directly linked (either conceptually or literally) to your graphic card's buffers. And of course, your graphic card's memory can physically display one session at a time. So switching from one X session to another requires X to suspend the first in order to display the second.
To get what you want, you need to somehow capture the suspended session. I don't believe there are any tools available to do this.
On the other hand, if you had multiple indpendent graphics cards installed with an independent X session on each card, then you probably can do what you have in mind.
There used to be software around which allowed multiple cards, keyboards and mice on one computer running multiple X sessions, but I've seen no references to this for years now. The original references I saw were to set up classrooms in Africa with a single computer and up to 6 monitors, keyboards and mice.
Long story short: What you want to do is interesting but fundamentally impossible without different equipment.
Note: In the day of mother boards with 8 PCI slots, we used to install 4 to 6 PCI based graphics cards to create a "wall" of screens. X made this easy with being able to instantiate independent X sessions for each card. Today, with a single card supporting multiple monitors, you loose that flexibility because you have effectively a single GPU and memory instance for that GPU regardless of the number of monitors you have. The card considers all your monitors as being in a single space.
I currently run a 3 monitor setup (1920x1080 each).
addendum:
If you don't mind using another computer, you can log in from the 2nd computer and capture screenshots of the first computer's X session that way. There is already existing software which will allow you to do this. Note that this works because you would be taking a screenshot of an active X session rather than a suspended X session. _________________ People whom think M$ is mediocre, don't know the half of it. |
|
Back to top |
|
|
Holysword l33t
Joined: 19 Nov 2006 Posts: 946 Location: Greece
|
Posted: Thu Nov 10, 2016 8:29 am Post subject: |
|
|
dufeu wrote: | Holysword wrote: | In display :1.0, I open a terminal and type "sleep 5 && scrot test.png". Then I quickly switch to display :2.0 by pressing ALT+CTRL+F2 and wait. Once I look at test.png, it is completely black.
I am imagining that X stops rendering the screen at :1.0 as soon as I switch to another session, because supposedly it is not needed... is that correct? |
When you perform an ALT+CTL+F(n), X automatically suspends the current AIGLX client: Code: | [176195.789] (II) AIGLX: Suspending AIGLX clients for VT switch |
Therefore you will always get a black screen.
Basically, X is managing window buffers directly linked (either conceptually or literally) to your graphic card's buffers. And of course, your graphic card's memory can physically display one session at a time. So switching from one X session to another requires X to suspend the first in order to display the second.
To get what you want, you need to somehow capture the suspended session. I don't believe there are any tools available to do this.
On the other hand, if you had multiple indpendent graphics cards installed with an independent X session on each card, then you probably can do what you have in mind.
There used to be software around which allowed multiple cards, keyboards and mice on one computer running multiple X sessions, but I've seen no references to this for years now. The original references I saw were to set up classrooms in Africa with a single computer and up to 6 monitors, keyboards and mice.
Long story short: What you want to do is interesting but fundamentally impossible without different equipment.
Note: In the day of mother boards with 8 PCI slots, we used to install 4 to 6 PCI based graphics cards to create a "wall" of screens. X made this easy with being able to instantiate independent X sessions for each card. Today, with a single card supporting multiple monitors, you loose that flexibility because you have effectively a single GPU and memory instance for that GPU regardless of the number of monitors you have. The card considers all your monitors as being in a single space.
I currently run a 3 monitor setup (1920x1080 each).
addendum:
If you don't mind using another computer, you can log in from the 2nd computer and capture screenshots of the first computer's X session that way. There is already existing software which will allow you to do this. Note that this works because you would be taking a screenshot of an active X session rather than a suspended X session. |
Very comprehensive explanation, thank you very much. I am also from those days, when we needed multiple GPU cards for multiheading - oh the dark times.
Sounds like an awful lot of trouble. Moreover, I'm running from a laptop, so adding a new card just to test this is unfeasible, sadly. I guess I'll have to live without such a feature. _________________ "Nolite arbitrari quia venerim mittere pacem in terram non veni pacem mittere sed gladium" (Yeshua Ha Mashiach) |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3342 Location: Rasi, Finland
|
Posted: Thu Nov 10, 2016 1:24 pm Post subject: |
|
|
Interesting... However being able to do this poses a security risk. Especially in places like libraries (I still hope no-one logs into bank from library PC) where they may have set up a multiseated setup to save money by having just one PC for multiple users. So another user could take screenshots from another seat's screen.
But I think it's already solved when you set the second seat and assign a GPU for it. Then the first seat should not have any accees to it... Finally SELinux should, at least, be able to deny screenshotting another seat's screen.
So... Just a thought.
dufeu wrote: | There used to be software around which allowed multiple cards, keyboards and mice on one computer running multiple X sessions, but I've seen no references to this for years now. The original references I saw were to set up classrooms in Africa with a single computer and up to 6 monitors, keyboards and mice. | This is practically a multiseated system.
And that's what I have here. :) One integrated GPU and one PCIe GPU. I managed to setup this using systemd.
I'm not sure if it's even possible with one GPU, because, at least in theory, you can assign GPU monitor connectors to different seats.
So if you give one connector to another X screen... there might be a way to screenshot that screen from another X session screen. This is primaly now a guessing game until someone tests it. I could try and test that on my setup.
EDIT:
Normal user on DISPLAY 1: shellcmd: import -window root -display :0.0 /tmp/shot.png : | Invalid MIT-MAGIC-COOKIE-1 keyimport: unable to open X server `:0.0' @ error/import.c/ImportImageCommand/358. |
Root user: shellcmd: import -window root -display :0.0 /tmp/shot.png : | No protocol specified
import: unable to open X server `:0.0' @ error/import.c/ImportImageCommand/358. |
No luck here either... fortunately. _________________ ..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9678 Location: almost Mile High in the USA
|
Posted: Thu Nov 10, 2016 4:25 pm Post subject: |
|
|
This should not be a privacy risk if things are set up properly. You need to have root (why not just dump all video and main memory to look for anything) or have access to the session cookie anyway (you just need to find it...).
Ideally each seat should have their own login of course, all bets are off if all share the same login.
I don't see this as an impossible task, this should be possible to do, just that there may not be a tool to easily do it. And if that screen were blanked due to screensaver, yeah that'd be blank. _________________ Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching? |
|
Back to top |
|
|
russK l33t
Joined: 27 Jun 2006 Posts: 665
|
Posted: Fri Nov 11, 2016 11:51 pm Post subject: |
|
|
I saw this method on Google+
Code: | chvt 7; sleep 2; import -display :0.0 -window root sshot1.png; chvt 1; |
HTH |
|
Back to top |
|
|
Holysword l33t
Joined: 19 Nov 2006 Posts: 946 Location: Greece
|
Posted: Thu Dec 01, 2016 3:23 pm Post subject: |
|
|
russK wrote: | I saw this method on Google+
Code: | chvt 7; sleep 2; import -display :0.0 -window root sshot1.png; chvt 1; |
HTH |
This didn't work for me. Did it work for you?
I tried a small code using Xlib and even having:
Code: | Display *display = XOpenDisplay(":0.0");
Window root = DefaultRootWindow(display);
|
hardset inside, it only results in black screens. _________________ "Nolite arbitrari quia venerim mittere pacem in terram non veni pacem mittere sed gladium" (Yeshua Ha Mashiach) |
|
Back to top |
|
|
Juippisi Developer
Joined: 30 Sep 2005 Posts: 724 Location: /home
|
Posted: Thu Dec 01, 2016 6:42 pm Post subject: |
|
|
works for me... |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3342 Location: Rasi, Finland
|
Posted: Thu Dec 01, 2016 9:23 pm Post subject: |
|
|
Juippisi wrote: |
works for me... |
shellcmd: DISPLAY=":1" scrot /tmp/security_issue.png : | Invalid MIT-MAGIC-COOKIE-1 keygiblib error: Can't open X display. It *is* running, yeah? | Yes. I have another seat open on DISPLAY :1. _________________ ..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
russK l33t
Joined: 27 Jun 2006 Posts: 665
|
Posted: Fri Dec 02, 2016 3:36 am Post subject: |
|
|
Holysword wrote: | russK wrote: | I saw this method on Google+
Code: | chvt 7; sleep 2; import -display :0.0 -window root sshot1.png; chvt 1; |
HTH |
This didn't work for me. Did it work for you?
|
Holysword,
Sorry no I did not even try it (my setup currently does not lend well to this), but after reading the thread from the beginning I guess I am not too surprised it did not work for you, especially if the result was another black image.
I used to use Xnest and Xephyr for this type of thing with some success, you might want to look into them. This I did try. I ran a simple graphical session within a Xephyr window with simple mwm and a couple windows. Then from outside that window I captured an image with gimp File->Create->Screenshot, and also your method with the import tool worked for me. My main environment is gnome 3.20 and I built xorg-server with the xephyr USE flag.
HTH |
|
Back to top |
|
|
russK l33t
Joined: 27 Jun 2006 Posts: 665
|
Posted: Fri Dec 02, 2016 3:40 am Post subject: |
|
|
Zucca wrote: | Juippisi wrote: |
works for me... |
shellcmd: DISPLAY=":1" scrot /tmp/security_issue.png : | Invalid MIT-MAGIC-COOKIE-1 keygiblib error: Can't open X display. It *is* running, yeah? | Yes. I have another seat open on DISPLAY :1. |
Zucca you may be able to pound it into submission with 'xauth' somehow, but sorry I don't have any more specifics. |
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9678 Location: almost Mile High in the USA
|
Posted: Fri Dec 02, 2016 4:31 am Post subject: |
|
|
As said earlier, if you can find the xauth cookie file and point to it, then you can easily do it.
If that display you don't care about security and have full control of it otherwise, you could just give up all control to that display by using xhost to do hostwide authentication.
But if you're getting black screens, this isn't the problem... _________________ Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching? |
|
Back to top |
|
|
Holysword l33t
Joined: 19 Nov 2006 Posts: 946 Location: Greece
|
Posted: Sun Dec 25, 2016 12:50 pm Post subject: |
|
|
I still don't get the black magic you guys are doing to achieve it!
I only get black screens.
I wrote this little C+Python script that is supposed to get a rectangle of the screen and convert it to a PIL image.
get_screen.c
pyGetScreen.py
Then after:
Code: | from pyGetScreen import *
getScreen(0,500,500,500,500).show()
getScreen(1,500,500,500,500).show() |
I get a black screen for the second but not for the first when I call it from :0.0.
If I call exactly the same thing from :1.0 I get a black screen for the first and not for the second.
I have no idea what you guys are talking about xauth. I am logged in both session with the same user. Is there anything else that needs to be done further? _________________ "Nolite arbitrari quia venerim mittere pacem in terram non veni pacem mittere sed gladium" (Yeshua Ha Mashiach) |
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9678 Location: almost Mile High in the USA
|
Posted: Sun Dec 25, 2016 4:18 pm Post subject: |
|
|
Each display has its own session cookie so you can't mess with the other display.
Actually, can you do this experiment: can you start 'xterm' or some other application on the other display?
If that works, your xauth/x security/MIT-session-cookie is working, and now I have no clue... _________________ Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching? |
|
Back to top |
|
|
Holysword l33t
Joined: 19 Nov 2006 Posts: 946 Location: Greece
|
Posted: Sun Dec 25, 2016 4:26 pm Post subject: |
|
|
eccerr0r wrote: | Each display has its own session cookie so you can't mess with the other display.
Actually, can you do this experiment: can you start 'xterm' or some other application on the other display?
If that works, your xauth/x security/MIT-session-cookie is working, and now I have no clue... |
I tried "xterm -display :1.0" from display :0.0 and it worked.
Does the code I posted work for you?
EDIT#1: I just found this line in my Xorg.1.log:
Code: | [323350.916] (--) intel(0): HDMI max TMDS frequency 225000KHz
[323350.918] (II) systemd-logind: got resume for 13:73
[323353.751] (II) AIGLX: Suspending AIGLX clients for VT switch
[323353.801] (II) systemd-logind: got pause for 13:66
[323353.801] (II) systemd-logind: got pause for 13:80
|
Does this sound like the reason for my black screen? If so, how to disable this feature? _________________ "Nolite arbitrari quia venerim mittere pacem in terram non veni pacem mittere sed gladium" (Yeshua Ha Mashiach) |
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9678 Location: almost Mile High in the USA
|
Posted: Sun Dec 25, 2016 11:12 pm Post subject: |
|
|
Ok, I think I see the same behavior when starting a second X server on the same GPU versus running a separate screen via Xnest or Xvnc on :1, :2, etc.
(gdm running on :0, my normal on :1, and a test X :2)
When use xwd on -display :2 from :1, it is black. It seems that indeed the X server does not keep state when not active on the VT.
I guess it makes a difference what X server, and to "fix" would require a server hack. _________________ Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching? |
|
Back to top |
|
|
dufeu l33t
Joined: 30 Aug 2002 Posts: 924 Location: US-FL-EST
|
Posted: Mon Dec 26, 2016 5:50 am Post subject: |
|
|
eccerr0r wrote: | When use xwd on -display :2 from :1, it is black. It seems that indeed the X server does not keep state when not active on the VT.
I guess it makes a difference what X server, and to "fix" would require a server hack. |
The issue here is a hardware limitation of the GPU {by design}.
TL;DR -- I'll try to explain it from a different perspective. When you do a screen capture, you're not taking a picture of something in regular RAM. Instead, you're directly reading the GPU's memory. A GPU's physical RAM is tied to just it's own single GPU environment.
When you start up another virtual terminal, the GPU doesn't have the physical architecture to have two completely different, independent GPU environments. Instead, X stops the current GPU environment, sets it aside, and feeds a new GPU environment to your GPU card's memory. Note that X does NOT stop the original environments processes/tasks. It merely disconnects the video output from the first user environment and then attaches the video output from the second user environment to your GPU.
When you attempt to take a screenshot of your first {running} GPU environment from within your second GPU environment, there's no 'there' there. There isn't any GPU memory supporting the first GPU environment. There is nothing for the screenshot process to read which results in black screens. You're trying to take a screenshot of the great bit bucket in the sky. It can't be done.
There are only two ways around this. One physical, the other by faking it in software. - Physical: You can use a second GPU either by; ) installing an independent GPU on your computer and setting up/executing to different graphical logins, one each for each GPU. X does support this and has supported this for years. PCI slot based GPU cards are great for this; or B) logging into your first computer over a network using a second computer. Either way, you'd be using 2 independent GPUs.
- Faking it. As was mentioned earlier in this thread, there is software available called 'fakexrandr'. This works by divvying up your GPU's memory model. This partitioning of your GPU's memory model does not happen on your GPU card but rather in regular RAM by faking X out.
Note that all GPU cards have a maximum memory model of displayable space. This model isn't in bytes but rather a total count of virtual pixels. This is how a multi-head setup works. Each display consumes a 'chunk' of the total virtual pixel space your GPU card supports. All displays are therefore 'windows' showing just a portion of the total virtual pixel space. Rather than set up multiple windows under a single GPU environment as X usually does for a multi-head setup, 'fakexrandr' moves the split of the GPUs total virtual pixel space up one level into multiple virtual GPU environments each pointing to a different part of the GPU's total virtual pixel space. Since X already supports the concept of multiple independent GPUs on a single system, this is {apparently} relatively easy to do.
Conceptually, this is the same thing as when you set up multiple virtual PCs each with it's own virtual graphics card. In the case of virtual PCs, you're running it's own display window in your currently used GPU vitrual pixel space. 'fakexrandr' just sets up virtual GPUs pointing to different chunks of GPUs virtual pixel space without running a virtual PC.
Two points about 'fakexrandr' worth mentioning. 1) From the project's site, there currently isn't support for 'xcb' dependent graphics packages. An 'equery d xcb' did not show any packages currently installed on my system with a dependency on 'xcb'. YMMV. 2) There doexn't seem to be any existing portage compatible ebuilds. Someone may have one but either I didn't use good search terms or no one has done one yet.
Long story short - Either use 2 physical GPUs or two virtual GPUs {which point to different chunks of your single GPUs virtual total pixel space}. While the 'need' is simple, there is no simple way to do this.
I didn't mean to address this again but I realized no one {including me} had mentioned a key point. Screenshots are taken from GPU memory or from the buffers which directly feed the GPU's memory. For the purposes of this discussion, it doesn't matter which since X only 'sees' the current chunk of the GPU cards memory model that it's currently addressing.
Hope this makes things clearer. _________________ People whom think M$ is mediocre, don't know the half of it. |
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9678 Location: almost Mile High in the USA
|
Posted: Mon Dec 26, 2016 7:13 am Post subject: |
|
|
Well, that's the thing. Depending on the hardware/software I don't see why it couldn't maintain state for a second context with the memory on board, especially if the GPU can do GPGPU operations - and thus the GPU processors can dedicate to its own section of GPU memory. Then it would be easier to switch context displayed on the output. But I guess it's clear now - they do not share.
The strange thing is that if a X client changes its state on a screen that's not the current VT, it would also end up discarding all events until it becomes foreground again and a redraw is issued. That was a bit confusing that the warning should have stopped all clients and not AIGLX only.
But still it was quite interesting by experimentation this was the case for GPU/graphics card video memory, and I was thinking that the "other" server was actually Xvnc or Xnest display which have a completely virtual frame buffer (or perhaps another video card with its own fb) which can be snooped upon, and not the same video hardware with different context. _________________ Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching? |
|
Back to top |
|
|
kernelOfTruth Watchman
Joined: 20 Dec 2005 Posts: 6111 Location: Vienna, Austria; Germany; hello world :)
|
|
Back to top |
|
|
Holysword l33t
Joined: 19 Nov 2006 Posts: 946 Location: Greece
|
Posted: Tue Dec 27, 2016 9:56 am Post subject: |
|
|
Okay, so long story short, this is a limitation of X itself, by design?
If so, are there any hopes that this will be simpler with Wayland instead? _________________ "Nolite arbitrari quia venerim mittere pacem in terram non veni pacem mittere sed gladium" (Yeshua Ha Mashiach) |
|
Back to top |
|
|
|