Patchwork [bitbake-devel,4/6] ui/crumbs/persistenttooltip: try to reflect WM close button position

login
register
mail settings
Submitter Joshua Lock
Date March 20, 2012, 12:18 a.m.
Message ID <82586a6a712fb5413e3f8698f6e0794c45676144.1332202341.git.josh@linux.intel.com>
Download mbox | patch
Permalink /patch/23827/
State Accepted
Commit 09147098a63c33dc05dc39b7fe4da4df8e2dbd4c
Headers show

Comments

Joshua Lock - March 20, 2012, 12:18 a.m.
When the user is running a desktop where the close button is on the left we
try to detect that and position the tooltip close button appropriately.
Where we can't easily determine this we default to placing the close button
on the right.

Tested on Ubuntu/Unity and Fedora/Gnome Shell.

Signed-off-by: Joshua Lock <josh@linux.intel.com>
---
 lib/bb/ui/crumbs/persistenttooltip.py |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
Dongxiao Xu - March 20, 2012, 5:59 a.m.
On Mon, 2012-03-19 at 17:18 -0700, Joshua Lock wrote:
> When the user is running a desktop where the close button is on the left we
> try to detect that and position the tooltip close button appropriately.
> Where we can't easily determine this we default to placing the close button
> on the right.
> 
> Tested on Ubuntu/Unity and Fedora/Gnome Shell.
> 
> Signed-off-by: Joshua Lock <josh@linux.intel.com>

Acked-by: Dongxiao Xu <dongxiao.xu@intel.com>

> ---
>  lib/bb/ui/crumbs/persistenttooltip.py |   24 +++++++++++++++++++++++-
>  1 files changed, 23 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/bb/ui/crumbs/persistenttooltip.py b/lib/bb/ui/crumbs/persistenttooltip.py
> index 0167363..bae697e 100644
> --- a/lib/bb/ui/crumbs/persistenttooltip.py
> +++ b/lib/bb/ui/crumbs/persistenttooltip.py
> @@ -20,6 +20,10 @@
>  
>  import gobject
>  import gtk
> +try:
> +    import gconf
> +except:
> +    pass
>  
>  class PersistentTooltip(gtk.Window):
>  	"""
> @@ -34,6 +38,21 @@ class PersistentTooltip(gtk.Window):
>  	def __init__(self, markup):
>  		gtk.Window.__init__(self, gtk.WINDOW_POPUP)
>  
> +		# The placement of the close button on the tip should reflect how the
> +		# window manager of the users system places close buttons. Try to read
> +		# the metacity gconf key to determine whether the close button is on the
> +		# left or the right.
> +		# In the case that we can't determine the users configuration we default
> +		# to close buttons being on the right.
> +		__button_right = True
> +		try:
> +		    client = gconf.client_get_default()
> +		    order = client.get_string("/apps/metacity/general/button_layout")
> +		    if order and order.endswith(":"):
> +		        __button_right = False
> +		except NameError:
> +			pass
> +
>  		# We need to ensure we're only shown once
>  		self.shown = False
>  
> @@ -65,7 +84,10 @@ class PersistentTooltip(gtk.Window):
>  		self.button.set_can_default(True)
>  		self.button.grab_focus()
>  		self.button.show()
> -		hbox.pack_end(self.button, False, False, 0)
> +		if __button_right:
> +		    hbox.pack_end(self.button, False, False, 0)
> +		else:
> +		    hbox.pack_start(self.button, False, False, 0)
>  
>  		self.set_default(self.button)
>

Patch

diff --git a/lib/bb/ui/crumbs/persistenttooltip.py b/lib/bb/ui/crumbs/persistenttooltip.py
index 0167363..bae697e 100644
--- a/lib/bb/ui/crumbs/persistenttooltip.py
+++ b/lib/bb/ui/crumbs/persistenttooltip.py
@@ -20,6 +20,10 @@ 
 
 import gobject
 import gtk
+try:
+    import gconf
+except:
+    pass
 
 class PersistentTooltip(gtk.Window):
 	"""
@@ -34,6 +38,21 @@  class PersistentTooltip(gtk.Window):
 	def __init__(self, markup):
 		gtk.Window.__init__(self, gtk.WINDOW_POPUP)
 
+		# The placement of the close button on the tip should reflect how the
+		# window manager of the users system places close buttons. Try to read
+		# the metacity gconf key to determine whether the close button is on the
+		# left or the right.
+		# In the case that we can't determine the users configuration we default
+		# to close buttons being on the right.
+		__button_right = True
+		try:
+		    client = gconf.client_get_default()
+		    order = client.get_string("/apps/metacity/general/button_layout")
+		    if order and order.endswith(":"):
+		        __button_right = False
+		except NameError:
+			pass
+
 		# We need to ensure we're only shown once
 		self.shown = False
 
@@ -65,7 +84,10 @@  class PersistentTooltip(gtk.Window):
 		self.button.set_can_default(True)
 		self.button.grab_focus()
 		self.button.show()
-		hbox.pack_end(self.button, False, False, 0)
+		if __button_right:
+		    hbox.pack_end(self.button, False, False, 0)
+		else:
+		    hbox.pack_start(self.button, False, False, 0)
 
 		self.set_default(self.button)