From 73b9047c8d221558fa3bd3ed0f6a17d76fe84910 Mon Sep 17 00:00:00 2001 From: Stefano Karapetsas Date: Thu, 16 Jan 2014 10:02:43 +0100 Subject: mate-window-picker-applet: Add GTK3 support --- mate-window-picker-applet/applet.c | 16 ++++++ mate-window-picker-applet/task-item.c | 66 ++++++++++++++++++++---- mate-window-picker-applet/task-title.c | 92 ++++++++++++++++++++++++++++++---- 3 files changed, 155 insertions(+), 19 deletions(-) (limited to 'mate-window-picker-applet') diff --git a/mate-window-picker-applet/applet.c b/mate-window-picker-applet/applet.c index be98536..2edd45e 100644 --- a/mate-window-picker-applet/applet.c +++ b/mate-window-picker-applet/applet.c @@ -35,6 +35,10 @@ #include #include +#if GTK_CHECK_VERSION (3, 0, 0) +#define gtk_rc_style_unref g_object_ref +#endif + #include "task-list.h" #include "task-title.h" @@ -60,7 +64,11 @@ static gpointer parent_class; static void cw_panel_background_changed (MatePanelApplet *applet, MatePanelAppletBackgroundType type, GdkColor *colour, +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_pattern_t *pattern, +#else GdkPixmap *pixmap, +#endif gpointer user_data); static void display_about_dialog (GtkAction *action, WinPickerApp *applet); @@ -229,7 +237,11 @@ static void cw_panel_background_changed (MatePanelApplet *applet, MatePanelAppletBackgroundType type, GdkColor *colour, +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_pattern_t *pattern, +#else GdkPixmap *pixmap, +#endif gpointer user_data) { GtkRcStyle *rc_style; @@ -256,12 +268,16 @@ cw_panel_background_changed (MatePanelApplet *applet, break; case PANEL_PIXMAP_BACKGROUND: +#if GTK_CHECK_VERSION (3, 0, 0) + /* FIXME */ +#else style = gtk_style_copy (GTK_WIDGET (applet)->style); if (style->bg_pixmap[GTK_STATE_NORMAL]) g_object_unref (style->bg_pixmap[GTK_STATE_NORMAL]); style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref (pixmap); gtk_widget_set_style (GTK_WIDGET (applet), style); g_object_unref (style); +#endif /*style = gtk_style_copy (mainapp->title->style); if (style->bg_pixmap[GTK_STATE_NORMAL]) diff --git a/mate-window-picker-applet/task-item.c b/mate-window-picker-applet/task-item.c index a584d23..cafcb2c 100644 --- a/mate-window-picker-applet/task-item.c +++ b/mate-window-picker-applet/task-item.c @@ -66,7 +66,9 @@ update_hints (TaskItem *item) { GtkWidget *parent; GtkWidget *widget; + GtkAllocation *allocation; WnckWindow *window; + GdkWindow *gdkwindow; gint x, y, x1, y1; widget = GTK_WIDGET (item); @@ -76,32 +78,37 @@ update_hints (TaskItem *item) if (!GTK_IS_WIDGET (widget)) return; /* Skip invisible windows */ - if (!GTK_WIDGET_VISIBLE (widget)) return; + if (!gtk_widget_get_visible (widget)) return; x = y = 0; /* Recursively compute the button's coordinates */ - for (parent = widget; parent; parent = parent->parent) + for (parent = widget; parent; parent = gtk_widget_get_parent (parent)) { - if (parent->parent) + if (gtk_widget_get_parent (parent)) { - x += parent->allocation.x; - y += parent->allocation.y; + gtk_widget_get_allocation (parent, allocation); + x += allocation->x; + y += allocation->y; } else { x1 = y1 = 0; - if (GDK_IS_WINDOW (parent->window)) - gdk_window_get_origin (parent->window, &x1, &y1); + gdkwindow = gtk_widget_get_window (parent); +#if !GTK_CHECK_VERSION (3, 0, 0) + if (GDK_IS_WINDOW (gdkwindow)) +#endif + gdk_window_get_origin (gdkwindow, &x1, &y1); x += x1; y += y1; break; } } /* Set the minimize hint for the window */ + gtk_widget_get_allocation (widget, allocation); wnck_window_set_icon_geometry (window, x, y, - widget->allocation.width, - widget->allocation.height); + allocation->width, + allocation->height); } static gboolean @@ -191,6 +198,26 @@ task_item_set_visibility (TaskItem *item) } } +#if GTK_CHECK_VERSION (3, 0, 0) + +static void +task_item_get_preferred_width (GtkWidget *widget, + gint *minimal_width, + gint *natural_width) +{ + *minimal_width = *natural_width = DEFAULT_TASK_ITEM_WIDTH; +} + +static void +task_item_get_preferred_height (GtkWidget *widget, + gint *minimal_height, + gint *natural_height) +{ + *minimal_height = *natural_height = DEFAULT_TASK_ITEM_HEIGHT; +} + +#else + static void task_item_size_request (GtkWidget *widget, GtkRequisition *requisition) @@ -200,6 +227,8 @@ task_item_size_request (GtkWidget *widget, requisition->height = DEFAULT_TASK_ITEM_HEIGHT; } +#endif + static GdkPixbuf * task_item_sized_pixbuf_for_window (TaskItem *item, WnckWindow *window, @@ -247,10 +276,17 @@ task_item_sized_pixbuf_for_window (TaskItem *item, return pbuf; } static gboolean +#if GTK_CHECK_VERSION (3, 0, 0) +task_item_draw (GtkWidget *widget, + cairo_t *cr) +#else task_item_expose_event (GtkWidget *widget, GdkEventExpose *event) +#endif { +#if !GTK_CHECK_VERSION (3, 0, 0) cairo_t *cr; +#endif TaskItem *item; GdkRectangle area; TaskItemPrivate *priv; @@ -259,7 +295,9 @@ task_item_expose_event (GtkWidget *widget, g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (TASK_IS_ITEM (widget), FALSE); +#if !GTK_CHECK_VERSION (3, 0, 0) g_return_val_if_fail (event != NULL, FALSE); +#endif item = TASK_ITEM (widget); priv = item->priv; @@ -267,7 +305,9 @@ task_item_expose_event (GtkWidget *widget, g_return_val_if_fail (WNCK_IS_WINDOW (priv->window), FALSE); area = priv->area; +#if !GTK_CHECK_VERSION (3, 0, 0) cr = gdk_cairo_create (event->window); +#endif pbuf = priv->pixbuf; desat = NULL; @@ -354,7 +394,9 @@ task_item_expose_event (GtkWidget *widget, if (GDK_IS_PIXBUF (desat)) g_object_unref (desat); +#if !GTK_CHECK_VERSION (3, 0, 0) cairo_destroy (cr); +#endif return FALSE; } @@ -679,8 +721,14 @@ task_item_class_init (TaskItemClass *klass) GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); obj_class->finalize = task_item_finalize; +#if GTK_CHECK_VERSION (3, 0, 0) + widget_class->draw = task_item_draw; + widget_class->get_preferred_width = task_item_get_preferred_width; + widget_class->get_preferred_height = task_item_get_preferred_height; +#else widget_class->expose_event = task_item_expose_event; widget_class->size_request = task_item_size_request; +#endif g_type_class_add_private (obj_class, sizeof (TaskItemPrivate)); diff --git a/mate-window-picker-applet/task-title.c b/mate-window-picker-applet/task-title.c index 5db675f..546e331 100644 --- a/mate-window-picker-applet/task-title.c +++ b/mate-window-picker-applet/task-title.c @@ -23,6 +23,12 @@ #include #include +#if GTK_CHECK_VERSION (3, 0, 0) +#include +#define MATE_DESKTOP_USE_UNSTABLE_API +#include +#endif + #include "task-list.h" G_DEFINE_TYPE (TaskTitle, task_title, GTK_TYPE_EVENT_BOX); @@ -70,7 +76,11 @@ on_close_clicked (GtkButton *button, if (!WNCK_IS_WINDOW (window) || wnck_window_get_window_type (window) == WNCK_WINDOW_DESKTOP) { +#if GTK_CHECK_VERSION (3, 0, 0) + mate_gdk_spawn_command_line_on_screen (gdk_screen_get_default (), +#else gdk_spawn_command_line_on_screen (gdk_screen_get_default (), +#endif LOGOUT, NULL); } else @@ -111,8 +121,13 @@ on_leave_notify (GtkWidget *widget, } static gboolean +#if GTK_CHECK_VERSION (3, 0, 0) +on_button_draw (GtkWidget *widget, + cairo_t *cr, +#else on_button_expose (GtkWidget *widget, GdkEventExpose *event, +#endif TaskTitle *title) { g_return_val_if_fail (TASK_IS_TITLE (title), FALSE); @@ -123,17 +138,39 @@ on_button_expose (GtkWidget *widget, if (priv->mouse_in_close_button) { GtkStyle *style = gtk_widget_get_style (widget); - gtk_paint_box (style, +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRectangle area; + gdouble x1, y1, x2, y2; + cairo_clip_extents (cr, &x1, &y1, &x2, &y2); + area.x = floor (x1); + area.y = floor (y1); + area.width = ceil (x2) - area.x; + area.height = ceil (y2) - area.y; +#endif + gtk_paint_box (style, +#if GTK_CHECK_VERSION (3, 0, 0) + cr, +#else event->window, +#endif GTK_STATE_PRELIGHT, GTK_SHADOW_NONE, +#if !GTK_CHECK_VERSION (3, 0, 0) NULL, +#endif NULL, NULL, +#if GTK_CHECK_VERSION (3, 0, 0) + area.x, + area.y + 2, + area.width, + area.height - 4); +#else event->area.x, event->area.y + 2, event->area.width, - event->area.height - 4); + event->area.height - 4); +#endif } return FALSE; } @@ -356,20 +393,46 @@ on_button_release (GtkWidget *title, GdkEventButton *event) static gboolean +#if GTK_CHECK_VERSION (3, 0, 0) +on_draw (GtkWidget *eb, cairo_t *cr) +#else on_expose (GtkWidget *eb, GdkEventExpose *event) +#endif { - - if (eb->state == GTK_STATE_ACTIVE) - gtk_paint_box (eb->style, eb->window, - eb->state, GTK_SHADOW_NONE, - NULL, eb, "button", - eb->allocation.x, eb->allocation.y, - eb->allocation.width, eb->allocation.height); + GtkAllocation *allocation; + GtkStyle *style; + GtkStateType state; + + gtk_widget_get_allocation (eb, allocation); + style = gtk_widget_get_style (eb); + state = gtk_widget_get_state (eb); + + if (state == GTK_STATE_ACTIVE) + gtk_paint_box (style, +#if GTK_CHECK_VERSION (3, 0, 0) + cr, +#else + eb->window, +#endif + state, GTK_SHADOW_NONE, +#if !GTK_CHECK_VERSION (3, 0, 0) + NULL, +#endif + eb, "button", + allocation->x, allocation->y, + allocation->width, allocation->height); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_container_propagate_draw (GTK_CONTAINER (eb), + gtk_bin_get_child (GTK_BIN (eb)), + cr); + +#else gtk_container_propagate_expose (GTK_CONTAINER (eb), gtk_bin_get_child (GTK_BIN (eb)), event); +#endif return TRUE; } @@ -394,7 +457,11 @@ task_title_class_init (TaskTitleClass *klass) GtkWidgetClass *wid_class = GTK_WIDGET_CLASS (klass); obj_class->finalize = task_title_finalize; +#if GTK_CHECK_VERSION (3, 0, 0) + wid_class->draw = on_draw; +#else wid_class->expose_event = on_expose; +#endif g_type_class_add_private (obj_class, sizeof (TaskTitlePrivate)); } @@ -461,11 +528,16 @@ task_title_init (TaskTitle *title) G_CALLBACK (on_enter_notify), title); g_signal_connect (priv->button, "leave-notify-event", G_CALLBACK (on_leave_notify), title); +#if GTK_CHECK_VERSION (3, 0, 0) + g_signal_connect (priv->button, "draw", + G_CALLBACK (on_button_draw), title); +#else g_signal_connect (priv->button, "expose-event", G_CALLBACK (on_button_expose), title); +#endif /* Load the quit icon. We have to do this in such a god-forsaken way - because of http://bugzilla.mate.org/show_bug.cgi?id=581359 and the + because of http://bugzilla.gnome.org/show_bug.cgi?id=581359 and the fact that we support as far back as GTK+ 2.12 (which never passes FORCE_SIZE in GtkImage). The only way to guarantee icon size is to load and scale it ourselves. We don't do this for all the other icons -- cgit v1.2.1