Index: src/bacon-volume.c
===================================================================
RCS file: /cvs/gnome/totem/src/bacon-volume.c,v
retrieving revision 1.15
diff -p -u -B -r1.15 bacon-volume.c
--- src/bacon-volume.c	1 Nov 2006 10:23:09 -0000	1.15
+++ src/bacon-volume.c	2 Nov 2006 15:10:34 -0000
@@ -84,8 +84,8 @@ bacon_volume_button_get_type (void)
 {
   static GType bacon_volume_button_type = 0;
 
-  if (!bacon_volume_button_type) {
-    static const GTypeInfo bacon_volume_button_info = {
+  if (G_UNLIKELY (bacon_volume_button_type == 0)) {
+    const GTypeInfo bacon_volume_button_info = {
       sizeof (BaconVolumeButtonClass),
       NULL,
       NULL,
@@ -181,6 +181,7 @@ bacon_volume_button_new (GtkIconSize siz
 		       _("Volume"));
   button->size = size;
   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+  gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
 
 #ifndef HAVE_GTK_ONLY
   /* image */
@@ -302,8 +303,15 @@ bacon_volume_button_press (GtkWidget    
   gint x, y, m, dx, dy, sx, sy, ystartoff, mouse_y;
   float v;
   GdkEventButton *e;
+  GdkDisplay *display;
+  GdkScreen *screen;
+
+  display = gtk_widget_get_display (widget);
+  screen = gtk_widget_get_screen (widget);
 
   /* position roughly */
+  gtk_window_set_screen (GTK_WINDOW (button->dock), screen);
+
   gdk_window_get_origin (widget->window, &x, &y);
   x += widget->allocation.x;
   y += widget->allocation.y;
@@ -332,12 +340,25 @@ bacon_volume_button_press (GtkWidget    
   GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
 
   /* grab focus */
-  gtk_widget_grab_focus (button->dock);
   gtk_grab_add (button->dock);
-  gdk_pointer_grab (button->dock->window, TRUE,
-      GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
-      GDK_POINTER_MOTION_MASK, NULL, NULL, GDK_CURRENT_TIME);
-  gdk_keyboard_grab (button->dock->window, TRUE, GDK_CURRENT_TIME);
+
+  if (gdk_pointer_grab (button->dock->window, TRUE,
+			GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+			GDK_POINTER_MOTION_MASK, NULL, NULL, event->time)
+      != GDK_GRAB_SUCCESS) {
+	  gtk_grab_remove (button->dock);
+	  gtk_widget_hide (button->dock);
+	  return FALSE;
+   }
+
+  if (gdk_keyboard_grab (button->dock->window, TRUE, event->time) != GDK_GRAB_SUCCESS) {
+	  gdk_display_pointer_ungrab (display, event->time);
+	  gtk_grab_remove (button->dock);
+	  gtk_widget_hide (button->dock);
+	  return FALSE;
+  }
+
+  gtk_widget_grab_focus (button->dock);
 
   /* forward event to the slider */
   e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
@@ -368,11 +389,18 @@ bacon_volume_key_release (GtkWidget     
   GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (button->scale));
   gint x, y, m, dx, dy, sx, sy, ystartoff;
   float v;
+  GdkDisplay *display;
+  GdkScreen *screen;
 
   if (event->keyval != GDK_space && event->keyval != GDK_Return)
     return FALSE;
 
+  display = gtk_widget_get_display (widget);
+  screen = gtk_widget_get_screen (widget);
+
   /* position roughly */
+  gtk_window_set_screen (GTK_WINDOW (button->dock), screen);
+
   gdk_window_get_origin (widget->window, &x, &y);
   x += widget->allocation.x;
   y += widget->allocation.y;
@@ -397,12 +425,23 @@ bacon_volume_key_release (GtkWidget     
   gdk_window_get_origin (button->scale->window, &sx, &sy);
 
   /* grab focus */
-  gtk_widget_grab_focus (button->dock);
   gtk_grab_add (button->dock);
-  gdk_pointer_grab (button->dock->window, TRUE,
-      GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
-      NULL, NULL, GDK_CURRENT_TIME);
-  gdk_keyboard_grab (button->dock->window, TRUE, GDK_CURRENT_TIME);
+
+  if (gdk_pointer_grab (button->dock->window, TRUE,
+			GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
+			NULL, NULL, event->time)
+      != GDK_GRAB_SUCCESS) {
+	  gtk_grab_remove (button->dock);
+	  gtk_widget_hide (button->dock);
+	  return FALSE;
+   }
+
+  if (gdk_keyboard_grab (button->dock->window, TRUE, event->time) != GDK_GRAB_SUCCESS) {
+	  gdk_display_pointer_ungrab (display, event->time);
+	  gtk_grab_remove (button->dock);
+	  gtk_widget_hide (button->dock);
+	  return FALSE;
+  }
 
   gtk_widget_grab_focus (button->scale);
 
@@ -488,10 +527,12 @@ bacon_volume_release_grab (BaconVolumeBu
 			   GdkEventButton * event)
 {
   GdkEventButton *e;
+  GdkDisplay *display;
 
   /* ungrab focus */
-  gdk_keyboard_ungrab (GDK_CURRENT_TIME);
-  gdk_pointer_ungrab (GDK_CURRENT_TIME);
+  display = gtk_widget_get_display (GTK_WIDGET (button));
+  gdk_display_keyboard_ungrab (display, event->time);
+  gdk_display_pointer_ungrab (display, event->time);
   gtk_grab_remove (button->dock);
 
   /* hide again */
@@ -530,10 +571,12 @@ cb_dock_key_release (GtkWidget      * wi
   BaconVolumeButton *button = BACON_VOLUME_BUTTON (data);
 
   if (event->keyval == GDK_Escape) {
-     /* ungrab focus */
-    gdk_keyboard_ungrab (GDK_CURRENT_TIME);
-    gdk_pointer_ungrab (GDK_CURRENT_TIME);
-    gtk_grab_remove (button->dock);
+    GdkDisplay *display;
+
+    /* ungrab focus */
+    display = gtk_widget_get_display (widget);
+    gdk_display_keyboard_ungrab (display, event->time);
+    gdk_display_pointer_ungrab (display, event->time);
 
     /* hide again */
     gtk_widget_hide (button->dock);
@@ -586,8 +629,8 @@ bacon_volume_scale_get_type (void)
 {
   static GType bacon_volume_scale_type = 0;
 
-  if (!bacon_volume_scale_type) {
-    static const GTypeInfo bacon_volume_scale_info = {
+  if (G_UNLIKELY (bacon_volume_scale_type == 0)) {
+    const GTypeInfo bacon_volume_scale_info = {
       sizeof (GtkVScaleClass),
       NULL,
       NULL,
