wrong usage of DISPLAY environment variable

Bug #420552 reported by Paulo Zanoni
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gDesklets
Fix Released
Low
Bjoern Koch

Bug Description

Hello again!

Some introduction before the bug report:

The DISPLAY environment variable consists of 3 parts: host, display and screen, in the following format:

   host:display.screen

But the "host" and ".screen" parts are optional, so if you don't specify the host, it will mean "localhost" and if you don't specify the screen, it will mean "default screen of specified display". So, here are some examples of valid formats:

   192.168.1.10:2.3
   localhost:0.0
   :0.0
   :0

Gdesklets uses the value of the DISPLAY environment variable to name the socket it uses in communications, so if you have DISPLAY=:0, it will create a socket named "%3A0" inside ~/.gdesklets/sockets. And if you have DISPLAY=:0.0 it will create a socket named "%3A0.0" inside the same folder.

So, what is the problem?

In 99.9% of the desktop environments in the world, we only have one display (display 0) with only one screen (screen 0), so in those desktops DISPLAY=:0 means exactly the same thing as DISPLAY=:0.0 (because screen 0 is the default screen of display 0). But gdesklets treats these 2 as different things!

Do this:

   DISPLAY=:0 gdesklets start
   DISPLAY=:0 gdesklets status
      (it will report daemon as running)
   DISPLAY=:0.0 gdesklets status
      (it will report deamon as *NOT* running)

And, since I assume you know the difference between an X display and an X screen, you have already seen that this behavior is a bug, right??

Then, how do we fix that?

To answer this question, we need to ask another question: should a single instance of gdesklets be responsible for a single screen or for the whole display? And that is a question I can't answer since I'm not the maintainer of gdesklets =) But I've got suggestions of fixes for both possible answers:

If the answer is: "gdesklets should be responsible for the whole display", my suggestion is:
Don't put the screen number in the socket name! So if the user has "DISPLAY=:0.324", "DISPLAY=:0" or "DISPLAY=:0.0", gdesklets will only use the display number (:0) to name the socket, so everyone will be able to communicate with it.

If the answer is: "gdesklets should be responsible for a single screen", my suggestion is:
Always put the screen number in the socket name! So if the user has "DISPLAY=:0" we need to figure out which is the default screen for display :0 and then use it to name the socket. So if we figure out that screen 0 is the default screen for display 0, if the user has DISPLAY=:0 we'll use ":0.0" to name the socket.

And here is a "solution example":

Since I really needed to fix this problem for a particular system and I didn't have time to investigate the best way to solve it, I assumed the answer is "gdesklets should be responsible for a single screen" (only because patches are easier this way). So the solution is "always put the number of the screen in the socket name". Luckily, gtk can do that for us!

gdk.Display's "get_name()" method _seems_ to always return a string with the screen number included (it said it _seems_ to, so I'm not sure!). So if we do:
   gtk.gdk.Display(":0").get_name()
it will return ":0.0", which is fine and leads us to a patch! See the attached file.

This patch is just an example and it completly ignores the "host" part of the DISPLAY variable, but it is already better than what we have now in gdesklets! So, if you don't have time to find a better way to solve the problem, I suggest that you add this patch to gdesklets and only worry about this problem again if someone else complains (and I don't think that's going to happen soon...).

Thanks for your attention,
And sorry for the looooooong text =)
Paulo.

Revision history for this message
Paulo Zanoni (pzanoni) wrote :
Revision history for this message
Bjoern Koch (h.humpel) wrote :

Haven't digged deeper into this, but it looks good enough for me ;).
Fix committed in rev. 123.
Thanks for the patch!

Changed in gdesklets:
assignee: nobody → Bjoern Koch (h.humpel)
importance: Undecided → Low
milestone: none → release-of-0.36.2
status: New → Fix Committed
Revision history for this message
Joe Sapp (sappj) wrote :

I agree with the reporter (gd is responsible for a single screen). Thanks for the commit Bjoern.

Revision history for this message
Bjoern Koch (h.humpel) wrote :

Released with gDesklets 0.36.2.

Changed in gdesklets:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.