gnome-applets r10872 - trunk/mixer



Author: callum
Date: Thu Jun 26 11:14:17 2008
New Revision: 10872
URL: http://svn.gnome.org/viewvc/gnome-applets?rev=10872&view=rev

Log:
Changes to the volume slider widget: Make it behave more like the other dock windows attached to the panel, i.e. on-top and sticky but not modal. Remove some voodoo that relies on knowledge of the internals of the GTK+ window. Simplify the code, making it even more data driven.

Modified:
   trunk/mixer/ChangeLog
   trunk/mixer/applet.c
   trunk/mixer/dock.c
   trunk/mixer/dock.h

Modified: trunk/mixer/applet.c
==============================================================================
--- trunk/mixer/applet.c	(original)
+++ trunk/mixer/applet.c	Thu Jun 26 11:14:17 2008
@@ -577,13 +577,6 @@
 
   /* grab input */
   gtk_widget_grab_focus (GTK_WIDGET (applet->dock->scale));
-  gtk_grab_add (widget);
-  gdk_pointer_grab (widget->window, TRUE,
-		    GDK_BUTTON_PRESS_MASK |
-		    GDK_BUTTON_RELEASE_MASK |
-		    GDK_POINTER_MOTION_MASK,
-		    NULL, NULL, GDK_CURRENT_TIME);
-  gdk_keyboard_grab (widget->window, TRUE, GDK_CURRENT_TIME);
 
   /* set menu item as active */
   gtk_widget_set_state (GTK_WIDGET (applet), GTK_STATE_SELECTED);
@@ -600,11 +593,6 @@
   if (!applet->pop)
     return;
 
-  /* release input */
-  gdk_keyboard_ungrab (GDK_CURRENT_TIME);
-  gdk_pointer_ungrab (GDK_CURRENT_TIME);
-  gtk_grab_remove (widget);
-
   /* hide */
   gtk_widget_hide_all (GTK_WIDGET (applet->dock));
 
@@ -875,17 +863,10 @@
   if (applet->dock) {
     adj = gtk_range_get_adjustment (applet->dock->scale);
     g_object_ref (G_OBJECT (adj));
-    /* FIXME:
-     * - we need to unset the parent in some way, because else Gtk+
-     *    thinks that the child of the applet (image) is us (dock),
-     *    which is not the case.
-     */
-    gtk_widget_unparent (GTK_WIDGET (applet->dock));
+    gtk_widget_destroy (GTK_WIDGET (applet->dock));
   }
   dock = gnome_volume_applet_dock_new (IS_PANEL_HORIZONTAL (orientation) ?
       GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
-  /* parent, for signal forwarding */
-  gtk_widget_set_parent (dock, GTK_WIDGET (applet));
   applet->dock = GNOME_VOLUME_APPLET_DOCK (dock);
   gnome_volume_applet_dock_change (applet->dock, adj);
 

Modified: trunk/mixer/dock.c
==============================================================================
--- trunk/mixer/dock.c	(original)
+++ trunk/mixer/dock.c	Thu Jun 26 11:14:17 2008
@@ -66,7 +66,14 @@
 {
   dock->orientation = -1;
   dock->timeout = 0;
-  gtk_window_set_decorated (GTK_WINDOW (dock), FALSE);
+
+  /* We can't use a simple GDK_WINDOW_TYPE_HINT_DOCK here since
+   * the dock windows don't accept input by default. Instead we use the 
+   * popup-menu type as a base. */
+  gtk_window_set_type_hint (GTK_WINDOW (dock), 
+      			    GDK_WINDOW_TYPE_HINT_POPUP_MENU);
+  gtk_window_set_keep_above (GTK_WINDOW (dock), TRUE);
+  gtk_window_stick (GTK_WINDOW (dock));
 }
 
 GtkWidget *
@@ -74,22 +81,22 @@
 {
   GtkWidget *table, *button, *scale, *frame;
   GnomeVolumeAppletDock *dock;
-  struct {
+  gint i;
+  static struct {
     gint w, h;
-    gint x[3], y[3];
+    gint x[3], y[3]; /* Locations for widgets in the table. The widget 
+			coordinate order is '+', '-', then the slider. */
     GtkWidget * (* sfunc) (GtkAdjustment *adj);
     gint sw, sh;
+    gboolean inverted;
   } magic[2] = {
-    { 3, 1, { 2, 1, 0 }, { 0, 0, 0 }, gtk_hscale_new, 100, -1 },
-    { 1, 3, { 0, 0, 0 }, { 0, 1, 2 }, gtk_vscale_new, -1, 100 }
+    { 3, 1, { 2, 0, 1 }, { 0, 0, 0 }, gtk_hscale_new, 100, -1, FALSE},
+    { 1, 3, { 0, 0, 0 }, { 0, 2, 1 }, gtk_vscale_new, -1, 100, TRUE}
   };
 
   dock = g_object_new (GNOME_VOLUME_APPLET_TYPE_DOCK,
-		       "type-hint", GDK_WINDOW_TYPE_HINT_UTILITY,
 		       NULL);
   dock->orientation = orientation;
-  GTK_WINDOW (dock)->type = GTK_WINDOW_POPUP;
-  GTK_WIDGET_UNSET_FLAGS (dock, GTK_TOPLEVEL);
 
   frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
@@ -97,19 +104,24 @@
   table = gtk_table_new (magic[orientation].w,
 			 magic[orientation].h, FALSE);
 
-  button = gtk_button_new_with_label (_("+"));
+  button = gtk_button_new_with_label (_("-"));
+  dock->minus = GTK_BUTTON (button);
+  button = gtk_button_new_with_label (_("+")); /* The value of button falls
+						  through into the loop. */
   dock->plus = GTK_BUTTON (button);
-  gtk_button_set_relief (dock->plus, GTK_RELIEF_NONE);
-  gtk_table_attach_defaults (GTK_TABLE (table), button,
-			     magic[orientation].x[0],
-			     magic[orientation].x[0] + 1,
-			     magic[orientation].y[0],
-			     magic[orientation].y[0] + 1);
-  g_signal_connect (button, "button-press-event",
-		    G_CALLBACK (cb_button_press), dock);
-  g_signal_connect (button, "button-release-event",
-		    G_CALLBACK (cb_button_release), dock);
-  gtk_widget_show (button);
+  for (i = 0; i<2; i++) { /* for button in (dock->plus, dock->minus): */
+    gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+    gtk_table_attach_defaults (GTK_TABLE (table), button,
+			       magic[orientation].x[i],
+			       magic[orientation].x[i] + 1,
+			       magic[orientation].y[i],
+			       magic[orientation].y[i] + 1);
+    g_signal_connect (button, "button-press-event",
+		      G_CALLBACK (cb_button_press), dock);
+    g_signal_connect (button, "button-release-event",
+		      G_CALLBACK (cb_button_release), dock);
+    button = GTK_WIDGET (dock->minus);
+  }
 
   scale = magic[orientation].sfunc (NULL);
   dock->scale = GTK_RANGE (scale);
@@ -117,55 +129,41 @@
 			       magic[orientation].sw,
 			       magic[orientation].sh);
   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
-  if (orientation == GTK_ORIENTATION_VERTICAL)
-    gtk_range_set_inverted (dock->scale, TRUE);
+  gtk_range_set_inverted (dock->scale, magic[orientation].inverted);
   gtk_table_attach_defaults (GTK_TABLE (table), scale,
-			     magic[orientation].x[1],
-			     magic[orientation].x[1] + 1,
-			     magic[orientation].y[1],
-			     magic[orientation].y[1] + 1);
-  gtk_widget_show (scale);
-
-  button = gtk_button_new_with_label (_("-"));
-  dock->minus = GTK_BUTTON (button);
-  gtk_button_set_relief (dock->minus, GTK_RELIEF_NONE);
-  gtk_table_attach_defaults (GTK_TABLE (table), button,
 			     magic[orientation].x[2],
 			     magic[orientation].x[2] + 1,
 			     magic[orientation].y[2],
 			     magic[orientation].y[2] + 1);
-  g_signal_connect (button, "button-press-event",
-		    G_CALLBACK (cb_button_press), dock);
-  g_signal_connect (button, "button-release-event",
-		    G_CALLBACK (cb_button_release), dock);
-  gtk_widget_show (button);
 
   gtk_container_add (GTK_CONTAINER (frame), table);
-  gtk_widget_show (table);
-
   gtk_container_add (GTK_CONTAINER (dock), frame);
-  gtk_widget_show (frame);
 
   return GTK_WIDGET (dock);
 }
 
-static void
-gnome_volume_applet_dock_dispose (GObject *object)
+static destroy_source (GnomeVolumeAppletDock *dock)
 {
-  GnomeVolumeAppletDock *dock = GNOME_VOLUME_APPLET_DOCK (object);
-
-  gnome_volume_applet_dock_change (dock, NULL);
-
   if (dock->timeout) {
     g_source_remove (dock->timeout);
     dock->timeout = 0;
   }
+}
+
+static void
+gnome_volume_applet_dock_dispose (GObject *object)
+{
+  GnomeVolumeAppletDock *dock = GNOME_VOLUME_APPLET_DOCK (object);
+
+  destroy_source (dock);
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 /*
- * React if user presses +/- buttons.
+ * Change the value of the slider. This is called both from a direct
+ * call from the +/- button callbacks and via a timer so holding down the 
+ * buttons changes the volume.
  */
 
 static gboolean
@@ -190,6 +188,7 @@
     volume = adj->upper;
     res = FALSE;
   }
+
   gtk_range_set_value (dock->scale, volume);
 
   if (!res)
@@ -198,6 +197,10 @@
   return res;
 }
 
+/*
+ * React if user presses +/- buttons.
+ */
+
 static gboolean
 cb_button_press (GtkWidget *widget,
 		 GdkEventButton *button,
@@ -206,8 +209,7 @@
   GnomeVolumeAppletDock *dock = data;
 
   dock->direction = (GTK_BUTTON (widget) == dock->plus) ? 1 : -1;
-  if (dock->timeout)
-    g_source_remove (dock->timeout);
+  destroy_source (dock);
   dock->timeout = g_timeout_add (100, cb_timeout, data);
   cb_timeout (data);
 
@@ -221,16 +223,13 @@
 {
   GnomeVolumeAppletDock *dock = data;
 
-  if (dock->timeout) {
-    g_source_remove (dock->timeout);
-    dock->timeout = 0;
-  }
+  destroy_source (dock);
 
   return TRUE;
 }
 
 /*
- * Change the active element.
+ * Set the adjustment for the slider.
  */
 
 void

Modified: trunk/mixer/dock.h
==============================================================================
--- trunk/mixer/dock.h	(original)
+++ trunk/mixer/dock.h	Thu Jun 26 11:14:17 2008
@@ -27,12 +27,6 @@
 #include <gtk/gtkbutton.h>
 #include <gtk/gtkrange.h>
 #include <gtk/gtkwindow.h>
-#include <gst/gst.h>
-#ifdef HAVE_GST10
-#include <gst/interfaces/mixer.h>
-#else
-#include <gst/mixer/mixer.h>
-#endif
 
 G_BEGIN_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]