static void action_changed (MsdMediaKeysWindow *window) { if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { switch (window->priv->action) { case MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME: volume_controls_set_visible (window, TRUE); if (window->priv->volume_muted) { window_set_icon_name (window, "audio-volume-muted"); } else { window_set_icon_name (window, "audio-volume-high"); } break; case MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM: volume_controls_set_visible (window, window->priv->show_level); window_set_icon_name (window, window->priv->icon_name); break; default: g_assert_not_reached (); break; } } msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); }
static void volume_muted_changed (MsdMediaKeysWindow *window) { msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { if (window->priv->volume_muted) { window_set_icon_name (window, "audio-volume-muted"); } else { window_set_icon_name (window, "audio-volume-high"); } } }
static void volume_level_changed (MsdMediaKeysWindow *window) { msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window)) && window->priv->progress != NULL) { double fraction; fraction = (double) window->priv->volume_level / 100.0; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (window->priv->progress), fraction); } }
static void msd_media_keys_window_init (MsdMediaKeysWindow *window) { GdkScreen *screen; window->priv = MSD_MEDIA_KEYS_WINDOW_GET_PRIVATE (window); screen = gtk_widget_get_screen (GTK_WIDGET (window)); if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { GtkBuilder *builder; const gchar *objects[] = {"acme_box", NULL}; GtkWidget *box; builder = gtk_builder_new (); gtk_builder_add_objects_from_file (builder, GTKBUILDERDIR "/acme.ui", (char **) objects, NULL); window->priv->image = GTK_IMAGE (gtk_builder_get_object (builder, "acme_image")); window->priv->progress = GTK_WIDGET (gtk_builder_get_object (builder, "acme_volume_progressbar")); box = GTK_WIDGET (gtk_builder_get_object (builder, "acme_box")); if (box != NULL) { gtk_container_add (GTK_CONTAINER (window), box); gtk_widget_show_all (box); } /* The builder needs to stay alive until the window takes ownership of the box (and its children) */ g_object_unref (builder); } }
static void msd_osd_window_real_hide (GtkWidget *widget) { MsdOsdWindow *window; if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide) { GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide (widget); } window = MSD_OSD_WINDOW (widget); remove_hide_timeout (window); }
void msd_media_keys_window_set_action (MsdMediaKeysWindow *window, MsdMediaKeysWindowAction action) { g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); g_return_if_fail (action == MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); if (window->priv->action != action) { window->priv->action = action; action_changed (window); } else { msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); } }
/* This is our draw-event handler when the window is in a compositing manager. * We draw everything by hand, using Cairo, so that we can have a nice * transparent/rounded look. */ static void draw_when_composited (GtkWidget *widget, cairo_t *orig_cr) { MsdOsdWindow *window; cairo_t *cr; cairo_surface_t *surface; int width; int height; GtkStyleContext *context; window = MSD_OSD_WINDOW (widget); context = gtk_widget_get_style_context (widget); cairo_set_operator (orig_cr, CAIRO_OPERATOR_SOURCE); gtk_window_get_size (GTK_WINDOW (widget), &width, &height); surface = cairo_surface_create_similar (cairo_get_target (orig_cr), CAIRO_CONTENT_COLOR_ALPHA, width, height); if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { goto done; } cr = cairo_create (surface); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { goto done; } gtk_render_background (context, cr, 0, 0, width, height); gtk_render_frame (context, cr, 0, 0, width, height); g_signal_emit (window, signals[DRAW_WHEN_COMPOSITED], 0, cr); cairo_destroy (cr); /* Make sure we have a transparent background */ cairo_rectangle (orig_cr, 0, 0, width, height); cairo_set_source_rgba (orig_cr, 0.0, 0.0, 0.0, 0.0); cairo_fill (orig_cr); cairo_set_source_surface (orig_cr, surface, 0, 0); cairo_paint_with_alpha (orig_cr, window->priv->fade_out_alpha); done: if (surface != NULL) { cairo_surface_destroy (surface); } }
/** * gpm_backlight_dialog_init: * * Initialises the popup, and makes sure that it matches the compositing of the screen. **/ static void gpm_backlight_dialog_init (GpmBacklight *backlight) { if (backlight->priv->popup != NULL && !msd_osd_window_is_valid (MSD_OSD_WINDOW (backlight->priv->popup))) { gtk_widget_destroy (backlight->priv->popup); backlight->priv->popup = NULL; } if (backlight->priv->popup == NULL) { backlight->priv->popup= msd_media_keys_window_new (); msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (backlight->priv->popup), "gpm-brightness-lcd", TRUE); gtk_window_set_position (GTK_WINDOW (backlight->priv->popup), GTK_WIN_POS_NONE); } }
void msd_media_keys_window_set_action_custom (MsdMediaKeysWindow *window, const char *icon_name, gboolean show_level) { g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); g_return_if_fail (icon_name != NULL); if (window->priv->action != MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM || g_strcmp0 (window->priv->icon_name, icon_name) != 0 || window->priv->show_level != show_level) { window->priv->action = MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM; g_free (window->priv->icon_name); window->priv->icon_name = g_strdup (icon_name); window->priv->show_level = show_level; action_changed (window); } else { msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); } }
static gboolean msd_osd_window_expose_event (GtkWidget *widget, GdkEventExpose *event) { MsdOsdWindow *window; GtkWidget *child; window = MSD_OSD_WINDOW (widget); if (window->priv->is_composited) expose_when_composited (widget, event); else expose_when_not_composited (widget, event); child = gtk_bin_get_child (GTK_BIN (window)); if (child) gtk_container_propagate_expose (GTK_CONTAINER (window), child, event); return FALSE; }
static gboolean msd_osd_window_draw (GtkWidget *widget, cairo_t *cr) { MsdOsdWindow *window; GtkWidget *child; window = MSD_OSD_WINDOW (widget); if (window->priv->is_composited) draw_when_composited (widget, cr); else draw_when_not_composited (widget, cr); child = gtk_bin_get_child (GTK_BIN (window)); if (child) gtk_container_propagate_draw (GTK_CONTAINER (window), child, cr); return FALSE; }
/* This is our expose-event handler when the window is *not* in a compositing manager. * We just draw a rectangular frame by hand. We do this with hardcoded drawing code, * instead of GtkFrame, to avoid changing the window's internal widget hierarchy: in * either case (composited or non-composited), callers can assume that this works * identically to a GtkWindow without any intermediate widgetry. */ static void expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) { MsdOsdWindow *window; GtkAllocation allocation; window = MSD_OSD_WINDOW (widget); gtk_widget_get_allocation (widget, &allocation); gtk_paint_shadow (gtk_widget_get_style (widget), gtk_widget_get_window (widget), gtk_widget_get_state (widget), GTK_SHADOW_OUT, &event->area, widget, NULL, /* NULL detail -> themes should use the MsdOsdWindow widget name, probably */ 0, 0, allocation.width, allocation.height); }
/* This is our expose-event handler when the window is in a compositing manager. * We draw everything by hand, using Cairo, so that we can have a nice * transparent/rounded look. */ static void expose_when_composited (GtkWidget *widget, GdkEventExpose *event) { MsdOsdWindow *window; cairo_t *context; cairo_t *cr; cairo_surface_t *surface; int width; int height; GtkStyle *style; GdkColor color; double r, g, b; window = MSD_OSD_WINDOW (widget); context = gdk_cairo_create (gtk_widget_get_window (widget)); style = gtk_widget_get_style (widget); cairo_set_operator (context, CAIRO_OPERATOR_SOURCE); gtk_window_get_size (GTK_WINDOW (widget), &width, &height); surface = cairo_surface_create_similar (cairo_get_target (context), CAIRO_CONTENT_COLOR_ALPHA, width, height); if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { goto done; } cr = cairo_create (surface); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { goto done; } cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_paint (cr); /* draw a box */ msd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); msd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; cairo_set_source_rgba (cr, r, g, b, BG_ALPHA); cairo_fill_preserve (cr); msd_osd_window_color_reverse (&style->text_aa[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; cairo_set_source_rgba (cr, r, g, b, BG_ALPHA / 2); cairo_set_line_width (cr, 1); cairo_stroke (cr); g_signal_emit (window, signals[EXPOSE_WHEN_COMPOSITED], 0, cr); cairo_destroy (cr); /* Make sure we have a transparent background */ cairo_rectangle (context, 0, 0, width, height); cairo_set_source_rgba (context, 0.0, 0.0, 0.0, 0.0); cairo_fill (context); cairo_set_source_surface (context, surface, 0, 0); cairo_paint_with_alpha (context, window->priv->fade_out_alpha); done: if (surface != NULL) { cairo_surface_destroy (surface); } cairo_destroy (context); }