! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
apps launched from xfce might appear on the wrong screen
Status:
RESOLVED: FIXED

Comments

Description David Mohr 2007-11-12 04:22:20 CET
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071004 Iceweasel/2.0.0.8 (Debian-2.0.0.8-1)
Build Identifier: 

I run a dual monitor setup (not xinerama), so I have two X displays (first is :0.0 and second is :0.1).

When I launch some applications on my second screen, the appear on my first screen instead of on the second.

I say "might appear on the wrong screen" because I can't find a nice pattern on when it will appear on the correct screen and when on the wrong one (see steps to reproduce.

This is a regression, since 4.4.0 worked correctly.

Reproducible: Always

Steps to Reproduce:
 - open a pdf file in thunar with evince -> appears on the wrong screen
 - open a pdf file in thunar with acroread -> appears on right screen
 - open evince from xfdesktop -> appears on the right screen
 - open brasero from xfdesktop -> appears on the wrong screen
Actual Results:  
Sometimes the launched application appears on the correct X screen, sometimes on the wrong one (see steps to reproduce)

Expected Results:  
The application should always appear on the second X screen when launched from the second X screen.

Please contact me if I can help to debug this. I'd love to get this resolved. Not having to have to go back to a terminal to launch applications is the whole point of using xfce :-).
Comment 1 David Mohr 2007-11-12 04:23:52 CET
I should probably have mentioned that I'm running xfce on debian sid.
Comment 2 Jean-François Wauthy editbugs 2007-11-12 07:27:55 CET
Created attachment 1424 
patch fixing the issue in trunk

I experienced the same issue in trunk and fixed. Could you try the attached patch ?
Comment 3 Jean-François Wauthy editbugs 2007-11-12 07:29:14 CET
The patch has to be applied against libxfcegui4/xfce-exec.c
Comment 4 Olivier Fourdan editbugs 2007-11-12 22:24:33 CET
With all respects, I doubt this is a *major* issue. Does your system crash, do you loose your work, is there any security risk?...
Comment 5 David Mohr 2007-11-13 02:59:36 CET
> With all respects, I doubt this is a *major* issue. Does your system crash, do
> you loose your work, is there any security risk?...

You are right, my apologies. Changing severity to normal. I'll check the patch posted above soon.
Comment 6 David Mohr 2007-11-13 04:02:42 CET
Thanks for the patch Jean-François, but it doesn't solve the issue for me.
Comment 7 Brian J. Tarricone (not reading bugmail) 2007-11-13 05:24:51 CET
JF, regardless, if you get the chance, could you apply it to 4.4 branch as well?  Probably useful.
Comment 8 David Mohr 2007-11-13 05:53:37 CET
Created attachment 1426 
applying the same code as JF's patch to thunar-vfs-exec - defective

Let me correct myself: JF's patch fixed some cases (i.e. launching brasero from the xfdesktop menu), but not others (like opening a pdf file in either xfdesktop or thunar).

I looked into the issue and the reason his patch doesn't fix all cases is because thunar-vfs-exec doesn't use libxfcegui4's xfce-exec. The attached patch fixes my problems.
Comment 9 Brian J. Tarricone (not reading bugmail) 2007-11-13 06:07:13 CET
Ah, excellent.  Benny, ok to apply to thunar-vfs?  Or if you want to do it...
Comment 10 Benedikt Meurer editbugs 2007-11-13 07:56:30 CET
Hm... the patch doesn't look right. Now gdk_spawn_on_screen() is used AND the DISPLAY variable is set manually. gdk_spawn_on_screen() should set the DISPLAY variable. So, instead of placing a new value into the sn_envp, it should simply remove the entry for DISPLAY (if any).
Comment 11 David Mohr 2007-11-13 15:47:54 CET
benny, when I try unsetting DISPLAY it doesn't work at all anymore - I get in ~/.xsession-error:

cannot open display:
Run 'evince --help' to see a full list of available command line options.

I guess I'll look at the gtk code, to see what gdk_spawn_on_screen actually does.
Comment 12 David Mohr 2007-11-13 22:14:25 CET
After reading the gtk docs (which are all too sparse on comments IMHO), it seems like gdk_spawn_on_screen should take care of it all. But since that wasn't happening, I looked into the code:

gdk_spawn_on_screen is just a simple wrapper for g_spawn_async, which installs an additional function as child_setup. The wrapper uses g_setenv to set the display to the correct value, and then calls the user's child_setup. 
This wrapper child_setup is called right before the execve, so in reality the effect of g_setenv vanishes, because the execve replaces the environment with the one specified in envp, unless of course envp is null. But since xfce sets envp, it needs to include a correctly set DISPLAY.

I don't know if this should be reported as a bug to gtk or not. It might not be a bug, but a poorly documented feature, afterall ;-). But please use the patch I attached for the time being, it is necessary.

Note: I had to look through a bunch of functions to come to this conclusion, it's possible I overlooked something (and I'm by all means not particularly familiar with gtk/glib's internals).
Comment 13 Jean-François Wauthy editbugs 2007-11-14 07:36:42 CET
I suggest to apply the proposed patches to xfce_4_4 for the upcoming release and then eventually improve the changes as Benedikt suggested; unless some improved patch is sent/committed in the meantime.
Comment 14 David Mohr 2007-11-15 02:26:29 CET
Created attachment 1429 
fixed patch

Please disregard the earlier patch I posted. I didn't handle the case of envp==NULL correctly, sorry! (Difference is just one if statement to check...)
Comment 15 Brian J. Tarricone (not reading bugmail) 2007-11-15 02:53:01 CET
No need to change the name... just mark it obsolete when you attach the new patch.
Comment 16 Benedikt Meurer editbugs 2007-11-15 19:32:26 CET
I had time to look into gdk now, and just discovered that gdk_spawn_on_screen() calls gdk_spawn_make_environment_for_screen() to modify the DISPLAY variable in the child environment (as I would have expected it to be). So, there's no need to patch thunar-vfs, since it's done in GDK. If that doesn't work properly, try to figure out what's wrong. According to the ChangeLog, the fix in GDK is present since 2003:

	* gdk/x11/gdkspawn-x11.c:
	(gdk_spawn_make_environment_for_screen): private function
	to create an environment vector with DISPLAY set appropriately
	for the screen.
Comment 17 Jean-François Wauthy editbugs 2007-11-16 11:59:54 CET
I also think that this is a bug in Gdk. The xfce_exec code has been working fine since I have 2 monitors and the problem appeared after some update in my system (unfortunately I can't tell which package exactly; maybe gtk+ 2.12).
Comment 18 Benedikt Meurer editbugs 2007-11-16 12:16:33 CET
So this one is for GTK+ then.
Comment 19 Jean-François Wauthy editbugs 2007-11-16 12:20:29 CET
(In reply to comment #18)
> So this one is for GTK+ then.
> 
Did you fill a bug on GTK+'s bugzilla ?
Comment 20 Benedikt Meurer editbugs 2007-11-16 13:29:22 CET
Nope, feel free to do so. ;-)
Comment 21 Jean-François Wauthy editbugs 2007-11-17 14:13:26 CET
Created attachment 1435 
test code

I just ran a test program (see attachment) and gdk_spawn_on_screen seems to work as expected. So it seems the problem is in our side.
Comment 22 Benedikt Meurer editbugs 2007-11-17 14:48:20 CET
Ehm, you did not pass an env to gdk_spawn_on_screen().
Comment 23 Jean-François Wauthy editbugs 2007-11-17 19:09:08 CET
Created attachment 1436 
test code (take 2)

I think I found with this new test code (including envp this time) what is going on. If I don't provide envp the DISPLAY env variable is not set and gdk_spawn_on_screen works fine; if I use environ as envp (which contains a value for the DISPLAY env variable), gdk_spawn_on_screen ignores the screen parameter and uses the value of DISPLAY. 

According to GDK doc: "the child process is spawned in such an environment that on calling gdk_display_open() it would be returned a GdkDisplay with screen as the default screen". Therefore it looks like a bug in Gdk or a lack of documentation. I'm gonna fill a bug against GDK; in the meantime, as a workaround, I suggest to remove the DISPLAY variable from the envp given to gdk_spawn_on_screen in real_xfce_exec_with_envp.
Comment 24 Jean-François Wauthy editbugs 2007-11-17 19:22:35 CET
Bug filled in GNOME bugzilla as #497727

http://bugzilla.gnome.org/show_bug.cgi?id=497727
Comment 25 David Mohr 2007-11-17 19:37:34 CET
> in the meantime, as a workaround, I suggest to remove the DISPLAY variable from 
> the envp given to gdk_spawn_on_screen in real_xfce_exec_with_envp.

Are you sure that that will work? I think I tried that since benny suggested it, and the child ended up having an environment where DISPLAY was not set at all.
Comment 26 Jean-François Wauthy editbugs 2007-11-17 19:39:20 CET
(In reply to comment #25)

> Are you sure that that will work? I think I tried that since benny suggested
> it, and the child ended up having an environment where DISPLAY was not set at
> all.

Is it really a problem ?
Comment 27 Brian J. Tarricone (not reading bugmail) 2007-11-17 19:48:04 CET
(In reply to comment #26)
> (In reply to comment #25)
> 
> > Are you sure that that will work? I think I tried that since benny suggested
> > it, and the child ended up having an environment where DISPLAY was not set at
> > all.
> 
> Is it really a problem ?

It is if it's an app that wants to access X...
Comment 28 Jean-François Wauthy editbugs 2007-11-17 20:00:37 CET
(In reply to comment #27)

> It is if it's an app that wants to access X...
> 

Then the technique used to fix trunk is the most usable: overwriting the DISPLAY env variable with the destination screen name
Comment 29 Brian J. Tarricone (not reading bugmail) 2007-11-17 20:08:08 CET
(In reply to comment #28)
 
> Then the technique used to fix trunk is the most usable: overwriting the
> DISPLAY env variable with the destination screen name

I agree, at least until this gets fixed upstream...
Comment 30 Benedikt Meurer editbugs 2007-11-28 17:32:22 CET
Fixed with revision 26393.

2007-11-28	Benedikt Meurer <benny@xfce.org>

	* thunar-vfs/thunar-vfs-exec.c(thunar_vfs_exec_on_screen):
	  Make sure to pass the correct $DISPLAY value to processes
	  spawned by Thunar and xfdesktop. Bug #3667.

Comment 31 Brian J. Tarricone (not reading bugmail) 2007-11-28 23:11:51 CET
*** Bug 3699 has been marked as a duplicate of this bug. ***
Comment 32 Brian J. Tarricone (not reading bugmail) 2007-11-28 23:13:13 CET
JF, did this get applied to 4.4 branch yet?  I think I want to re-roll the libxfcegui4  4.4.2 package with this fix in it.
Comment 33 Jean-François Wauthy editbugs 2007-11-29 07:44:30 CET
(In reply to comment #32)
> JF, did this get applied to 4.4 branch yet?  I think I want to re-roll the
> libxfcegui4  4.4.2 package with this fix in it.
> 

Yes it has been applied with revision 26366

Bug #3667

Reported by:
David Mohr
Reported on: 2007-11-12
Last modified on: 2009-07-15
Duplicates (1):
  • 3699 Application-windows open on wrong screen

People

Assignee:
Olivier Fourdan
CC List:
1 user

Version

Attachments

patch fixing the issue in trunk (1.23 KB, text/x-patch)
2007-11-12 07:27 CET , Jean-François Wauthy
no flags
applying the same code as JF's patch to thunar-vfs-exec - defective (971 bytes, text/x-patch)
2007-11-13 05:53 CET , David Mohr
no flags
fixed patch (951 bytes, patch)
2007-11-15 02:26 CET , David Mohr
no flags
test code (755 bytes, text/x-csrc)
2007-11-17 14:13 CET , Jean-François Wauthy
no flags
test code (take 2) (963 bytes, text/x-csrc)
2007-11-17 19:09 CET , Jean-François Wauthy
no flags

Additional information