From 41416ba7f8944ac60a6c1d84409d05a2d9e4d787 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 22 Jun 2011 15:19:49 -0400 Subject: port to gtk3 --- src/Makefile.am | 4 ++-- src/indicator-sound.c | 56 +++++++++++++++++++++++++++++++++++-------------- src/metadata-widget.c | 12 ++++++----- src/metadata-widget.h | 6 +++++- src/transport-widget.c | 40 ++++++++++++++++++++++------------- src/transport-widget.h | 5 ++++- src/voip-input-widget.h | 5 +++++ src/volume-widget.h | 5 +++++ 8 files changed, 94 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index c546f0f..e35f871 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -118,11 +118,11 @@ DBUS_SPECS = \ gen-%.xml.h: %.xml @echo "Building $@ from $<" - @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@ + @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $(notdir $<))));" > $@ gen-%.xml.c: %.xml @echo "Building $@ from $<" - @echo "const char * _$(subst -,_,$(subst .,_,$(basename $<))) = " > $@ + @echo "const char * _$(subst -,_,$(subst .,_,$(basename $(notdir $<)))) = " > $@ @sed -e "s:\":\\\\\":g" -e s:^:\": -e s:\$$:\\\\n\": $< >> $@ @echo ";" >> $@ diff --git a/src/indicator-sound.c b/src/indicator-sound.c index f2ec0a2..b8c0351 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -23,7 +23,11 @@ with this program. If not, see . #include #include #include +#if GTK_CHECK_VERSION(3, 0, 0) +#include +#else #include +#endif #include #include @@ -459,6 +463,26 @@ new_voip_slider_widget (DbusmenuMenuitem * newitem, //UI callbacks /******************************************************************/ +static GtkWidget * +get_current_item (GtkContainer * container) +{ + GList *children = gtk_container_get_children (container); + GList *iter; + GtkWidget *rv = NULL; + + /* Suprisingly, GTK+ doesn't really let us query "what is the currently + selected item?". But it does note it internally by prelighting the + widget, so we watch for that. */ + for (iter = children; iter; iter = iter->next) { + if (gtk_widget_get_state (GTK_WIDGET (iter->data)) & GTK_STATE_PRELIGHT) { + rv = GTK_WIDGET (iter->data); + break; + } + } + + return rv; +} + /** key_press_cb: **/ @@ -473,7 +497,7 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); GtkWidget *menuitem; - menuitem = GTK_MENU_SHELL (widget)->active_menu_item; + menuitem = get_current_item (GTK_CONTAINER (widget)); if (IDO_IS_SCALE_MENU_ITEM(menuitem) == TRUE){ gdouble current_value = 0; @@ -502,19 +526,19 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) } switch (event->keyval) { - case GDK_Right: + case GDK_KEY_Right: digested = TRUE; new_value = current_value + five_percent; break; - case GDK_Left: + case GDK_KEY_Left: digested = TRUE; new_value = current_value - five_percent; break; - case GDK_plus: + case GDK_KEY_plus: digested = TRUE; new_value = current_value + five_percent; break; - case GDK_minus: + case GDK_KEY_minus: digested = TRUE; new_value = current_value - five_percent; break; @@ -542,12 +566,12 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) } switch (event->keyval) { - case GDK_Right: + case GDK_KEY_Right: transport_widget_react_to_key_press_event ( transport_widget, TRANSPORT_ACTION_NEXT ); digested = TRUE; break; - case GDK_Left: + case GDK_KEY_Left: transport_widget_react_to_key_press_event ( transport_widget, TRANSPORT_ACTION_PREVIOUS ); digested = TRUE; @@ -557,8 +581,8 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) TRANSPORT_ACTION_PLAY_PAUSE ); digested = TRUE; break; - case GDK_Up: - case GDK_Down: + case GDK_KEY_Up: + case GDK_KEY_Down: digested = FALSE; break; default: @@ -585,7 +609,7 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) GtkWidget *menuitem; - menuitem = GTK_MENU_SHELL (widget)->active_menu_item; + menuitem = get_current_item (GTK_CONTAINER (widget)); if (IS_TRANSPORT_WIDGET(menuitem) == TRUE) { TransportWidget* transport_widget = NULL; GList* elem; @@ -597,12 +621,12 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) } switch (event->keyval) { - case GDK_Right: + case GDK_KEY_Right: transport_widget_react_to_key_release_event ( transport_widget, TRANSPORT_ACTION_NEXT ); digested = TRUE; break; - case GDK_Left: + case GDK_KEY_Left: transport_widget_react_to_key_release_event ( transport_widget, TRANSPORT_ACTION_PREVIOUS ); digested = TRUE; @@ -612,8 +636,8 @@ key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) TRANSPORT_ACTION_PLAY_PAUSE ); digested = TRUE; break; - case GDK_Up: - case GDK_Down: + case GDK_KEY_Up: + case GDK_KEY_Down: digested = FALSE; break; default: @@ -643,9 +667,9 @@ indicator_sound_scroll (IndicatorObject *io, gint delta, GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (slider)); //g_debug("indicator-sound-scroll - current slider value %f", value); if (direction == INDICATOR_OBJECT_SCROLL_UP) { - value += adj->step_increment; + value += gtk_adjustment_get_step_increment (adj); } else { - value -= adj->step_increment; + value -= gtk_adjustment_get_step_increment (adj); } //g_debug("indicator-sound-scroll - update slider with value %f", value); volume_widget_update(VOLUME_WIDGET(priv->volume_widget), value, "scroll updates"); diff --git a/src/metadata-widget.c b/src/metadata-widget.c index f687d0c..5c1db2f 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -267,7 +267,7 @@ static void draw_album_border(GtkWidget *metadata, gboolean selected) { cairo_t *cr; - cr = gdk_cairo_create (metadata->window); + cr = gdk_cairo_create (gtk_widget_get_window (metadata)); GtkStyle *style; style = gtk_widget_get_style (metadata); @@ -357,7 +357,7 @@ static void draw_album_art_placeholder(GtkWidget *metadata) { cairo_t *cr; - cr = gdk_cairo_create (metadata->window); + cr = gdk_cairo_create (gtk_widget_get_window (metadata)); GtkStyle *style; style = gtk_widget_get_style (metadata); @@ -659,10 +659,12 @@ metadata_widget_icon_triangle_draw_cb (GtkWidget *widget, style = gtk_widget_get_style (widget); - cr = (cairo_t*) gdk_cairo_create (widget->window); + cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget)); - x = widget->allocation.x; - y = widget->allocation.y; + GtkAllocation allocation; + gtk_widget_get_allocation (widget, &allocation); + x = allocation.x; + y = allocation.y; // Draw player icon if (priv->icon_buf != NULL){ diff --git a/src/metadata-widget.h b/src/metadata-widget.h index 30b629c..b0123a3 100644 --- a/src/metadata-widget.h +++ b/src/metadata-widget.h @@ -19,8 +19,12 @@ with this program. If not, see . #ifndef __METADATA_WIDGET_H__ #define __METADATA_WIDGET_H__ -#include +#include +#if GTK_CHECK_VERSION(3, 0, 0) +#include +#else #include +#endif G_BEGIN_DECLS diff --git a/src/transport-widget.c b/src/transport-widget.c index f05c4c1..f9b5319 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -104,8 +104,10 @@ G_DEFINE_TYPE (TransportWidget, transport_widget, GTK_TYPE_MENU_ITEM); /* essentials */ static void transport_widget_set_twin_item ( TransportWidget* self, DbusmenuMenuitem* twin_item); +#if ! GTK_CHECK_VERSION(3, 0, 0) static gboolean transport_widget_expose ( GtkWidget *button, GdkEventExpose *event); -static void draw (GtkWidget* button, cairo_t *cr); +#endif +static gboolean draw (GtkWidget* button, cairo_t *cr); /* UI and dbusmenu callbacks */ static gboolean transport_widget_button_press_event (GtkWidget *menuitem, @@ -133,8 +135,8 @@ static void transport_widget_react_to_button_release ( TransportWidget* button, TransportAction command); static void transport_widget_toggle_play_pause ( TransportWidget* button, TransportState update); -static void transport_widget_select (GtkItem* menu, gpointer Userdata); -static void transport_widget_deselect (GtkItem* menu, gpointer Userdata); +static void transport_widget_select (GtkWidget* menu, gpointer Userdata); +static void transport_widget_deselect (GtkWidget* menu, gpointer Userdata); static TransportAction transport_widget_collision_detection (gint x, gint y); static void transport_widget_start_timing (TransportWidget* widget); static gboolean transport_widget_trigger_seek (gpointer userdata); @@ -155,7 +157,11 @@ transport_widget_class_init (TransportWidgetClass *klass) widget_class->button_release_event = transport_widget_button_release_event; widget_class->motion_notify_event = transport_widget_motion_notify_event; widget_class->leave_notify_event = transport_widget_leave_notify_event; +#if GTK_CHECK_VERSION(3, 0, 0) + widget_class->draw = draw; +#else widget_class->expose_event = transport_widget_expose; +#endif gobject_class->dispose = transport_widget_dispose; gobject_class->finalize = transport_widget_finalize; @@ -212,11 +218,11 @@ transport_widget_init (TransportWidget *self) "notify", G_CALLBACK (transport_widget_notify), NULL); - g_signal_connect (GTK_ITEM(self), + g_signal_connect (G_OBJECT(self), "select", G_CALLBACK (transport_widget_select), NULL); - g_signal_connect (GTK_ITEM(self), + g_signal_connect (G_OBJECT(self), "deselect", G_CALLBACK (transport_widget_deselect), NULL); @@ -236,11 +242,12 @@ transport_widget_finalize (GObject *object) G_OBJECT_CLASS (transport_widget_parent_class)->finalize (object); } +#if ! GTK_CHECK_VERSION(3, 0, 0) static gboolean transport_widget_expose (GtkWidget *button, GdkEventExpose *event) { cairo_t *cr; - cr = gdk_cairo_create (button->window); + cr = gdk_cairo_create (gtk_widget_get_window (button)); //g_debug("In the playbutton's expose method, x = %i, y=%i and width: %i and height: %i'"); cairo_rectangle (cr, @@ -253,6 +260,7 @@ transport_widget_expose (GtkWidget *button, GdkEventExpose *event) cairo_destroy (cr); return FALSE; } +#endif gboolean transport_widget_is_selected ( TransportWidget* widget ) @@ -434,7 +442,7 @@ transport_widget_button_release_event (GtkWidget *menuitem, } static void -transport_widget_select (GtkItem* item, gpointer Userdata) +transport_widget_select (GtkWidget* item, gpointer Userdata) { TransportWidget* transport = TRANSPORT_WIDGET(item); TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); @@ -442,7 +450,7 @@ transport_widget_select (GtkItem* item, gpointer Userdata) } static void -transport_widget_deselect (GtkItem* item, gpointer Userdata) +transport_widget_deselect (GtkWidget* item, gpointer Userdata) { TransportWidget* transport = TRANSPORT_WIDGET(item); TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); @@ -1214,20 +1222,22 @@ _surface_blur (cairo_surface_t* surface, cairo_surface_mark_dirty (surface); } -static void +static gboolean draw (GtkWidget* button, cairo_t *cr) { - g_return_if_fail(IS_TRANSPORT_WIDGET(button)); - g_return_if_fail( cr != NULL ); + g_return_val_if_fail(IS_TRANSPORT_WIDGET(button), FALSE); + g_return_val_if_fail(cr != NULL, FALSE); TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(button); cairo_surface_t* surf = NULL; cairo_t* cr_surf = NULL; - cairo_translate (cr, button->allocation.x, button->allocation.y); + GtkAllocation allocation; + gtk_widget_get_allocation (button, &allocation); + cairo_translate (cr, allocation.x, allocation.y); - //g_debug("button x allocation = %i", button->allocation.x); - //g_debug("button y allocation = %i", button->allocation.y); + //g_debug("button x allocation = %i", allocation.x); + //g_debug("button y allocation = %i", allocation.y); GtkStyle *style; @@ -1795,6 +1805,8 @@ draw (GtkWidget* button, cairo_t *cr) FALSE); _finalize (cr, &cr_surf, &surf, PAUSE_X-0.5f, PAUSE_Y); } + + return FALSE; } static void diff --git a/src/transport-widget.h b/src/transport-widget.h index e5e91dc..8c2ce48 100644 --- a/src/transport-widget.h +++ b/src/transport-widget.h @@ -20,8 +20,11 @@ with this program. If not, see . #define __TRANSPORT_WIDGET_H__ #include -#include +#if GTK_CHECK_VERSION(3, 0, 0) +#include +#else #include +#endif #include "common-defs.h" diff --git a/src/voip-input-widget.h b/src/voip-input-widget.h index 29912f0..0e90665 100644 --- a/src/voip-input-widget.h +++ b/src/voip-input-widget.h @@ -21,7 +21,12 @@ with this program. If not, see . #include #include +#include +#if GTK_CHECK_VERSION(3, 0, 0) +#include +#else #include +#endif G_BEGIN_DECLS diff --git a/src/volume-widget.h b/src/volume-widget.h index 7012473..3deb99c 100644 --- a/src/volume-widget.h +++ b/src/volume-widget.h @@ -21,7 +21,12 @@ with this program. If not, see . #include #include +#include +#if GTK_CHECK_VERSION(3, 0, 0) +#include +#else #include +#endif #include G_BEGIN_DECLS -- cgit v1.2.3