diff options
Diffstat (limited to 'src/themes')
| -rw-r--r-- | src/themes/coco/coco-theme.c | 124 | ||||
| -rw-r--r-- | src/themes/nodoka/nodoka-theme.c | 135 | ||||
| -rw-r--r-- | src/themes/slider/theme.c | 93 | ||||
| -rw-r--r-- | src/themes/standard/theme.c | 78 |
4 files changed, 282 insertions, 148 deletions
diff --git a/src/themes/coco/coco-theme.c b/src/themes/coco/coco-theme.c index 90f95cd..ff76d52 100644 --- a/src/themes/coco/coco-theme.c +++ b/src/themes/coco/coco-theme.c @@ -1,11 +1,8 @@ /* - * coco-theme.c - * This file is part of notification-daemon-engine-coco - * * Copyright (C) 2012 - Stefano Karapetsas <[email protected]> * Copyright (C) 2010 - Eduardo Grajeda * Copyright (C) 2008 - Martin Sourada - * Copyright (C) 2012-2021 MATE Developers + * Copyright (C) 2012-2025 MATE Developers * * notification-daemon-engine-coco is free software; you can redistribute it * and/or modify it under the terms of the GNU General Public License as @@ -91,6 +88,7 @@ void move_notification(GtkWidget *nw, int x, int y); void set_notification_timeout(GtkWindow *nw, glong timeout); void set_notification_hints(GtkWindow *nw, GVariant *hints); void notification_tick(GtkWindow *nw, glong remaining); +static void create_pie_countdown(WindowData* windata); #define STRIPE_WIDTH 32 #define WIDTH 300 @@ -110,6 +108,24 @@ void notification_tick(GtkWindow *nw, glong remaining); /* Support Nodoka Functions */ +static void +get_background_color (GtkStyleContext *context, + GtkStateFlags state, + GdkRGBA *color) +{ + GdkRGBA *c; + + g_return_if_fail (color != NULL); + g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); + + gtk_style_context_get (context, state, + "background-color", &c, + NULL); + + *color = *c; + gdk_rgba_free (c); +} + /* Handle clicking on link */ static gboolean activate_link (GtkLabel *label, const char *url, WindowData *windata) @@ -172,7 +188,28 @@ draw_pie(GtkWidget *pie, WindowData *windata, cairo_t *cr) return; gdouble arc_angle = 1.0 - (gdouble)windata->remaining / (gdouble)windata->timeout; - cairo_set_source_rgba (cr, 1.0, 0.4, 0.0, 0.3); + GtkStyleContext *context; + GdkRGBA orig, bg; + + // :selected { background-color:#aabbcc; } ignored -> 1.0, 1.0, 1.0, 0.3 + context = gtk_widget_get_style_context (windata->win); + gtk_style_context_save (context); + gtk_style_context_set_state (context, GTK_STATE_FLAG_SELECTED); + get_background_color (context, GTK_STATE_FLAG_SELECTED, &orig); + gtk_style_context_restore (context); + + // .notification-box .countdown:selected { background-color:#aabbcc; } + context = gtk_widget_get_style_context (pie); + gtk_style_context_save (context); + gtk_style_context_set_state (context, GTK_STATE_FLAG_SELECTED); + get_background_color (context, GTK_STATE_FLAG_SELECTED, &bg); + gtk_style_context_restore (context); + + if (gdk_rgba_equal (&orig, &bg)) + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.3); + else + cairo_set_source_rgba (cr, bg.red, bg.green, bg.blue, bg.alpha); + cairo_move_to(cr, PIE_RADIUS, PIE_RADIUS); cairo_arc_negative(cr, PIE_RADIUS, PIE_RADIUS, PIE_RADIUS, -G_PI/2, (-0.25 + arc_angle)*2*G_PI); @@ -255,7 +292,6 @@ paint_window (GtkWidget *widget, cairo_restore (cr); update_shape_region (surface, windata); - cairo_surface_destroy (surface); } @@ -282,31 +318,21 @@ configure_event_cb(GtkWidget *nw, } static gboolean -countdown_expose_cb(GtkWidget *pie, - cairo_t *cr, - WindowData *windata) +countdown_expose_cb(GtkWidget *pie, cairo_t *cr, WindowData *windata) { cairo_t *cr2; cairo_surface_t *surface; GtkAllocation alloc; - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - + cairo_set_operator (cr, CAIRO_OPERATOR_OVER); gtk_widget_get_allocation (pie, &alloc); - surface = cairo_surface_create_similar (cairo_get_target (cr), - CAIRO_CONTENT_COLOR_ALPHA, - alloc.width, - alloc.height); - + surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, alloc.width, alloc.height); cr2 = cairo_create (surface); - - cairo_translate (cr2, -alloc.x, -alloc.y); - fill_background (pie, windata, cr2); - cairo_translate (cr2, alloc.x, alloc.y); - draw_pie (pie, windata, cr2); + cairo_set_source_rgba (cr2, 0.0, 0.0, 0.0, 0.0); // transparent background color + cairo_paint (cr2); + draw_pie (pie, windata, cr2); // countdown cairo_fill (cr2); - cairo_destroy (cr2); cairo_save (cr); @@ -442,7 +468,7 @@ create_notification(UrlClickedCb url_clicked) gtk_box_pack_start (GTK_BOX(main_vbox), windata->main_hbox, FALSE, FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(windata->main_hbox), 13); - /* The icon goes at the left */ + /* The icon goes at the left */ windata->iconbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_show(windata->iconbox); gtk_box_pack_start(GTK_BOX(windata->main_hbox), windata->iconbox, @@ -452,7 +478,7 @@ create_notification(UrlClickedCb url_clicked) gtk_box_pack_start(GTK_BOX(windata->iconbox), windata->icon, FALSE, FALSE, 0); - /* The title and the text at the right */ + /* The title and the text at the right */ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_halign (vbox, GTK_ALIGN_START); gtk_widget_set_margin_start (vbox, 8); @@ -633,19 +659,7 @@ add_notification_action(GtkWindow *nw, const char *text, const char *key, if (gtk_widget_get_visible(windata->actions_box)) { gtk_widget_show(windata->actions_box); - - /* Don't try to re-add a pie_countdown */ - if (!windata->pie_countdown) { - windata->pie_countdown = gtk_drawing_area_new(); - gtk_widget_set_halign (windata->pie_countdown, GTK_ALIGN_END); - gtk_widget_show(windata->pie_countdown); - - gtk_box_pack_end (GTK_BOX (windata->actions_box), windata->pie_countdown, FALSE, TRUE, 0); - gtk_widget_set_size_request(windata->pie_countdown, - PIE_WIDTH, PIE_HEIGHT); - g_signal_connect(G_OBJECT(windata->pie_countdown), "draw", - G_CALLBACK(countdown_expose_cb), windata); - } + create_pie_countdown(windata); } if (windata->action_icons) { @@ -730,6 +744,27 @@ move_notification(GtkWidget *nw, int x, int y) /* Hide notification */ /* Set notification timeout */ +static void create_pie_countdown(WindowData* windata) +{ + if (windata->pie_countdown != NULL) + return; /* Already created */ + + windata->pie_countdown = gtk_drawing_area_new(); + gtk_widget_set_halign (windata->pie_countdown, GTK_ALIGN_END); + gtk_widget_set_valign (windata->pie_countdown, GTK_ALIGN_CENTER); + gtk_widget_show(windata->pie_countdown); + + #if GTK_CHECK_VERSION (4,0,0) + gtk_widget_add_css_class (windata->pie_countdown, "countdown"); + #else + gtk_style_context_add_class (gtk_widget_get_style_context (windata->pie_countdown), "countdown"); + #endif + + gtk_box_pack_end (GTK_BOX (windata->actions_box), windata->pie_countdown, FALSE, TRUE, 0); + gtk_widget_set_size_request(windata->pie_countdown, PIE_WIDTH, PIE_HEIGHT); + g_signal_connect(G_OBJECT(windata->pie_countdown), "draw", G_CALLBACK(countdown_expose_cb), windata); +} + void set_notification_timeout(GtkWindow *nw, glong timeout) { @@ -737,6 +772,21 @@ set_notification_timeout(GtkWindow *nw, glong timeout) g_assert(windata != NULL); windata->timeout = timeout; + + /* Check if we should show countdown for all timed notifications */ + if (timeout > 0) + { + GSettings *gsettings = g_settings_new ("org.mate.NotificationDaemon"); + gboolean show_countdown = g_settings_get_boolean (gsettings, "show-countdown"); + g_object_unref (gsettings); + + if (show_countdown) + { + /* Ensure actions_box is visible for countdown */ + gtk_widget_show(windata->actions_box); + create_pie_countdown(windata); + } + } } /* Set notification hints */ diff --git a/src/themes/nodoka/nodoka-theme.c b/src/themes/nodoka/nodoka-theme.c index 1859f28..d478862 100644 --- a/src/themes/nodoka/nodoka-theme.c +++ b/src/themes/nodoka/nodoka-theme.c @@ -1,10 +1,7 @@ /* - * nodoka-theme.c - * This file is part of notification-daemon-engine-nodoka - * * Copyright (C) 2012 - Stefano Karapetsas <[email protected]> * Copyright (C) 2008 - Martin Sourada - * Copyright (C) 2012-2021 MATE Developers + * Copyright (C) 2012-2025 MATE Developers * * notification-daemon-engine-nodoka is free software; you can redistribute it * and/or modify it under the terms of the GNU General Public License as @@ -31,7 +28,6 @@ #include <libxml/xmlmemory.h> #include <libxml/xpath.h> -/* Define basic nodoka types */ typedef void (*ActionInvokedCb)(GtkWindow *nw, const char *key); typedef void (*UrlClickedCb)(GtkWindow *nw, const char *url); @@ -105,6 +101,7 @@ void move_notification(GtkWidget *nw, int x, int y); void set_notification_timeout(GtkWindow *nw, glong timeout); void set_notification_hints(GtkWindow *nw, GVariant *hints); void notification_tick(GtkWindow *nw, glong remaining); +static void create_pie_countdown(WindowData* windata); #define STRIPE_WIDTH 32 #define WIDTH 400 @@ -124,6 +121,24 @@ void notification_tick(GtkWindow *nw, glong remaining); /* Support Nodoka Functions */ +static void +get_background_color (GtkStyleContext *context, + GtkStateFlags state, + GdkRGBA *color) +{ + GdkRGBA *c; + + g_return_if_fail (color != NULL); + g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); + + gtk_style_context_get (context, state, + "background-color", &c, + NULL); + + *color = *c; + gdk_rgba_free (c); +} + /* Handle clicking on link */ static gboolean activate_link (GtkLabel *label, const char *url, WindowData *windata) @@ -405,8 +420,12 @@ fill_background(GtkWidget *widget, WindowData *windata, cairo_t *cr) static void draw_stripe(GtkWidget *widget, WindowData *windata, cairo_t *cr) { + int stripe_x = 0; + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + stripe_x = windata->width - STRIPE_WIDTH - stripe_x; + cairo_save (cr); - cairo_rectangle (cr, 0, 0, STRIPE_WIDTH, windata->height); + cairo_rectangle (cr, stripe_x, 0, STRIPE_WIDTH, windata->height); cairo_clip (cr); gdouble color_mult = 1.0; @@ -514,7 +533,28 @@ draw_pie(GtkWidget *pie, WindowData *windata, cairo_t *cr) return; gdouble arc_angle = 1.0 - (gdouble)windata->remaining / (gdouble)windata->timeout; - cairo_set_source_rgba (cr, 1.0, 0.4, 0.0, 0.3); + GtkStyleContext *context; + GdkRGBA orig, bg; + + // :selected { background-color:#aabbcc; } ignored -> 1.0, 0.4, 0.0, 0.3 + context = gtk_widget_get_style_context (windata->win); + gtk_style_context_save (context); + gtk_style_context_set_state (context, GTK_STATE_FLAG_SELECTED); + get_background_color (context, GTK_STATE_FLAG_SELECTED, &orig); + gtk_style_context_restore (context); + + // .notification-box .countdown:selected { background-color:#aabbcc; } + context = gtk_widget_get_style_context (pie); + gtk_style_context_save (context); + gtk_style_context_set_state (context, GTK_STATE_FLAG_SELECTED); + get_background_color (context, GTK_STATE_FLAG_SELECTED, &bg); + gtk_style_context_restore (context); + + if (gdk_rgba_equal (&orig, &bg)) + cairo_set_source_rgba (cr, 1.0, 0.4, 0.0, 0.3); + else + cairo_set_source_rgba (cr, bg.red, bg.green, bg.blue, bg.alpha); + cairo_move_to(cr, PIE_RADIUS, PIE_RADIUS); cairo_arc_negative(cr, PIE_RADIUS, PIE_RADIUS, PIE_RADIUS, -G_PI/2, (-0.25 + arc_angle)*2*G_PI); @@ -580,11 +620,9 @@ paint_window (GtkWidget *widget, windata->height); cr2 = cairo_create (surface); - - /* transparent background */ - cairo_rectangle (cr2, 0, 0, windata->width, windata->height); - cairo_set_source_rgba (cr2, 0.0, 0.0, 0.0, 0.0); - cairo_fill (cr2); + cairo_rectangle (cr2, 0, 0, windata->width, windata->height); + cairo_set_source_rgba (cr2, 0.0, 0.0, 0.0, 0.0); // transparent background color + cairo_fill (cr2); if (windata->arrow.has_arrow) { nodoka_rounded_rectangle_with_arrow (cr2, 0, 0, @@ -614,7 +652,6 @@ paint_window (GtkWidget *widget, cairo_restore (cr); update_shape_region (surface, windata); - cairo_surface_destroy (surface); } @@ -649,30 +686,21 @@ static void on_composited_changed (GtkWidget* window, WindowData* windata) } static gboolean -countdown_expose_cb(GtkWidget *pie, - cairo_t *cr, - WindowData *windata) +countdown_expose_cb(GtkWidget *pie, cairo_t *cr, WindowData *windata) { cairo_t *cr2; cairo_surface_t *surface; GtkAllocation alloc; - cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - + cairo_set_operator (cr, CAIRO_OPERATOR_OVER); gtk_widget_get_allocation (pie, &alloc); - surface = cairo_surface_create_similar (cairo_get_target (cr), - CAIRO_CONTENT_COLOR_ALPHA, - alloc.width, - alloc.height); + surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, alloc.width, alloc.height); cr2 = cairo_create (surface); - - cairo_translate (cr2, -alloc.x, -alloc.y); - fill_background (pie, windata, cr2); - cairo_translate (cr2, alloc.x, alloc.y); - draw_pie (pie, windata, cr2); + cairo_set_source_rgba (cr2, 0.0, 0.0, 0.0, 0.0); // transparent background color + cairo_paint (cr2); + draw_pie (pie, windata, cr2); // countdown cairo_fill (cr2); - cairo_destroy (cr2); cairo_save (cr); @@ -1037,19 +1065,7 @@ add_notification_action(GtkWindow *nw, const char *text, const char *key, { gtk_widget_show(windata->actions_box); update_content_hbox_visibility(windata); - - /* Don't try to re-add a pie_countdown */ - if (!windata->pie_countdown) { - windata->pie_countdown = gtk_drawing_area_new(); - gtk_widget_set_halign (windata->pie_countdown, GTK_ALIGN_END); - gtk_widget_show(windata->pie_countdown); - - gtk_box_pack_end (GTK_BOX (windata->actions_box), windata->pie_countdown, FALSE, TRUE, 0); - gtk_widget_set_size_request(windata->pie_countdown, - PIE_WIDTH, PIE_HEIGHT); - g_signal_connect(G_OBJECT(windata->pie_countdown), "draw", - G_CALLBACK(countdown_expose_cb), windata); - } + create_pie_countdown(windata); } if (windata->action_icons) { @@ -1141,6 +1157,27 @@ move_notification(GtkWidget *nw, int x, int y) /* Hide notification */ /* Set notification timeout */ +static void create_pie_countdown(WindowData* windata) +{ + if (windata->pie_countdown != NULL) + return; /* Already created */ + + windata->pie_countdown = gtk_drawing_area_new(); + gtk_widget_set_halign (windata->pie_countdown, GTK_ALIGN_END); + gtk_widget_set_valign (windata->pie_countdown, GTK_ALIGN_CENTER); + gtk_widget_show(windata->pie_countdown); + + #if GTK_CHECK_VERSION (4,0,0) + gtk_widget_add_css_class (windata->pie_countdown, "countdown"); + #else + gtk_style_context_add_class (gtk_widget_get_style_context (windata->pie_countdown), "countdown"); + #endif + + gtk_box_pack_end (GTK_BOX (windata->actions_box), windata->pie_countdown, FALSE, TRUE, 0); + gtk_widget_set_size_request(windata->pie_countdown, PIE_WIDTH, PIE_HEIGHT); + g_signal_connect(G_OBJECT(windata->pie_countdown), "draw", G_CALLBACK(countdown_expose_cb), windata); +} + void set_notification_timeout(GtkWindow *nw, glong timeout) { @@ -1148,6 +1185,22 @@ set_notification_timeout(GtkWindow *nw, glong timeout) g_assert(windata != NULL); windata->timeout = timeout; + + /* Check if we should show countdown for all timed notifications */ + if (timeout > 0) + { + GSettings *gsettings = g_settings_new ("org.mate.NotificationDaemon"); + gboolean show_countdown = g_settings_get_boolean (gsettings, "show-countdown"); + g_object_unref (gsettings); + + if (show_countdown) + { + /* Ensure actions_box is visible for countdown */ + gtk_widget_show(windata->actions_box); + update_content_hbox_visibility(windata); + create_pie_countdown(windata); + } + } } /* Set notification hints */ diff --git a/src/themes/slider/theme.c b/src/themes/slider/theme.c index 09cc98a..4552af0 100644 --- a/src/themes/slider/theme.c +++ b/src/themes/slider/theme.c @@ -1,9 +1,8 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * +/* * Copyright (C) 2006-2007 Christian Hammond <[email protected]> * Copyright (C) 2009 Red Hat, Inc. * Copyright (C) 2011 Perberos <[email protected]> - * Copyright (C) 2012-2021 MATE Developers + * Copyright (C) 2012-2025 MATE Developers * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -84,6 +83,8 @@ void set_notification_timeout(GtkWindow *nw, glong timeout); void set_notification_hints(GtkWindow *nw, GVariant *hints); void notification_tick(GtkWindow *nw, glong remaining); gboolean get_always_stack(GtkWidget* nw); +static gboolean on_countdown_draw (GtkWidget *widget, cairo_t *cr, WindowData *windata); +static void create_pie_countdown(WindowData* windata); #define WIDTH 400 #define DEFAULT_X0 0 @@ -234,14 +235,10 @@ static void paint_window (GtkWidget *widget, windata->height); cr2 = cairo_create (surface); - - /* transparent background */ cairo_rectangle (cr2, 0, 0, windata->width, windata->height); - cairo_set_source_rgba (cr2, 0.0, 0.0, 0.0, 0.0); + cairo_set_source_rgba (cr2, 0.0, 0.0, 0.0, 0.0); // transparent background color cairo_fill (cr2); - fill_background (widget, windata, cr2); - cairo_destroy(cr2); cairo_save (cr); @@ -495,6 +492,22 @@ void set_notification_timeout(GtkWindow *nw, glong timeout) g_assert(windata != NULL); windata->timeout = timeout; + + /* Check if we should show countdown for all timed notifications */ + if (timeout > 0) + { + GSettings *gsettings = g_settings_new ("org.mate.NotificationDaemon"); + gboolean show_countdown = g_settings_get_boolean (gsettings, "show-countdown"); + g_object_unref (gsettings); + + if (show_countdown) + { + /* Ensure actions_box is visible for countdown */ + gtk_widget_show(windata->actions_box); + update_content_hbox_visibility(windata); + create_pie_countdown(windata); + } + } } void notification_tick(GtkWindow* nw, glong remaining) @@ -694,45 +707,37 @@ paint_countdown (GtkWidget *pie, cairo_t* cr2; cairo_surface_t* surface; - context = gtk_widget_get_style_context(windata->win); - + // :selected { background-color:#aabbcc; } or + // .notification-box .countdown:selected { background-color:#aabbcc; } + context = gtk_widget_get_style_context (pie); gtk_style_context_save (context); gtk_style_context_set_state (context, GTK_STATE_FLAG_SELECTED); - get_background_color (context, GTK_STATE_FLAG_SELECTED, &bg); - gtk_style_context_restore (context); gtk_widget_get_allocation(pie, &allocation); - cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - surface = cairo_surface_create_similar(cairo_get_target(cr), - CAIRO_CONTENT_COLOR_ALPHA, - allocation.width, - allocation.height); + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + surface = cairo_surface_create_similar (cairo_get_target(cr), + CAIRO_CONTENT_COLOR_ALPHA, + allocation.width, + allocation.height); cr2 = cairo_create (surface); - - fill_background (pie, windata, cr2); - if (windata->timeout > 0) { gdouble pct = (gdouble) windata->remaining / (gdouble) windata->timeout; - gdk_cairo_set_source_rgba (cr2, &bg); - cairo_move_to (cr2, PIE_RADIUS, PIE_RADIUS); cairo_arc_negative (cr2, PIE_RADIUS, PIE_RADIUS, PIE_RADIUS, -G_PI_2, -(pct * G_PI * 2) - G_PI_2); cairo_line_to (cr2, PIE_RADIUS, PIE_RADIUS); cairo_fill (cr2); } - - cairo_destroy(cr2); + cairo_destroy (cr2); cairo_save (cr); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); cairo_restore (cr); - cairo_surface_destroy(surface); } @@ -744,6 +749,27 @@ on_countdown_draw (GtkWidget *widget, cairo_t *cr, WindowData *windata) return FALSE; } +static void create_pie_countdown(WindowData* windata) +{ + if (windata->pie_countdown != NULL) + return; /* Already created */ + + windata->pie_countdown = gtk_drawing_area_new(); + gtk_widget_set_halign (windata->pie_countdown, GTK_ALIGN_END); + gtk_widget_set_valign (windata->pie_countdown, GTK_ALIGN_CENTER); + gtk_widget_show(windata->pie_countdown); + + #if GTK_CHECK_VERSION (4,0,0) + gtk_widget_add_css_class (windata->pie_countdown, "countdown"); + #else + gtk_style_context_add_class (gtk_widget_get_style_context (windata->pie_countdown), "countdown"); + #endif + + gtk_box_pack_end (GTK_BOX (windata->actions_box), windata->pie_countdown, FALSE, TRUE, 0); + gtk_widget_set_size_request(windata->pie_countdown, PIE_WIDTH, PIE_HEIGHT); + g_signal_connect(G_OBJECT(windata->pie_countdown), "draw", G_CALLBACK(on_countdown_draw), windata); +} + static void on_action_clicked(GtkWidget* w, GdkEventButton *event, ActionInvokedCb action_cb) { GtkWindow* nw = g_object_get_data(G_OBJECT(w), "_nw"); @@ -765,24 +791,11 @@ void add_notification_action(GtkWindow* nw, const char* text, const char* key, A g_assert(windata != NULL); - if (!gtk_widget_get_visible(windata->actions_box)) + if (gtk_widget_get_visible(windata->actions_box)) { gtk_widget_show(windata->actions_box); update_content_hbox_visibility(windata); - - /* Don't try to re-add a pie_countdown */ - if (!windata->pie_countdown) { - windata->pie_countdown = gtk_drawing_area_new(); - gtk_widget_set_halign (windata->pie_countdown, GTK_ALIGN_END); - gtk_widget_set_valign (windata->pie_countdown, GTK_ALIGN_CENTER); - gtk_widget_show(windata->pie_countdown); - - gtk_box_pack_end (GTK_BOX (windata->actions_box), windata->pie_countdown, FALSE, TRUE, 0); - gtk_widget_set_size_request(windata->pie_countdown, - PIE_WIDTH, PIE_HEIGHT); - g_signal_connect(G_OBJECT(windata->pie_countdown), "draw", - G_CALLBACK(on_countdown_draw), windata); - } + create_pie_countdown(windata); } if (windata->action_icons) { diff --git a/src/themes/standard/theme.c b/src/themes/standard/theme.c index c21a61c..90171c6 100644 --- a/src/themes/standard/theme.c +++ b/src/themes/standard/theme.c @@ -1,9 +1,8 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * +/* * Copyright (C) 2006-2007 Christian Hammond <[email protected]> * Copyright (C) 2009 Red Hat, Inc. * Copyright (C) 2011 Perberos <[email protected]> - * Copyright (C) 2012-2021 MATE Developers + * Copyright (C) 2012-2025 MATE Developers * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301, USA. */ + #include "config.h" #include <glib/gi18n.h> @@ -100,6 +100,8 @@ void move_notification(GtkWidget *nw, int x, int y); void set_notification_timeout(GtkWindow *nw, glong timeout); void set_notification_hints(GtkWindow *nw, GVariant *hints); void notification_tick(GtkWindow *nw, glong remaining); +static void create_pie_countdown(WindowData* windata); +static gboolean on_countdown_draw (GtkWidget *widget, cairo_t *cr, WindowData *windata); //#define ENABLE_GRADIENT_LOOK @@ -153,7 +155,6 @@ static void fill_background(GtkWidget* widget, WindowData* windata, cairo_t* cr) #ifdef ENABLE_GRADIENT_LOOK cairo_pattern_t *gradient; int gradient_y; - gradient_y = allocation.height - BOTTOM_GRADIENT_HEIGHT; #endif @@ -836,6 +837,27 @@ void set_notification_hints(GtkWindow *nw, GVariant *hints) } } +static void create_pie_countdown(WindowData* windata) +{ + if (windata->pie_countdown != NULL) + return; /* Already created */ + + windata->pie_countdown = gtk_drawing_area_new(); + gtk_widget_set_halign (windata->pie_countdown, GTK_ALIGN_END); + gtk_widget_set_valign (windata->pie_countdown, GTK_ALIGN_CENTER); + gtk_widget_show(windata->pie_countdown); + + #if GTK_CHECK_VERSION (4,0,0) + gtk_widget_add_css_class (windata->pie_countdown, "countdown"); + #else + gtk_style_context_add_class (gtk_widget_get_style_context (windata->pie_countdown), "countdown"); + #endif + + gtk_box_pack_end (GTK_BOX (windata->actions_box), windata->pie_countdown, FALSE, TRUE, 0); + gtk_widget_set_size_request(windata->pie_countdown, PIE_WIDTH, PIE_HEIGHT); + g_signal_connect(G_OBJECT(windata->pie_countdown), "draw", G_CALLBACK(on_countdown_draw), windata); +} + void set_notification_timeout(GtkWindow* nw, glong timeout) { WindowData* windata = g_object_get_data(G_OBJECT(nw), "windata"); @@ -843,6 +865,22 @@ void set_notification_timeout(GtkWindow* nw, glong timeout) g_assert(windata != NULL); windata->timeout = timeout; + + /* Check if we should show countdown for all timed notifications */ + if (timeout > 0) + { + GSettings *gsettings = g_settings_new ("org.mate.NotificationDaemon"); + gboolean show_countdown = g_settings_get_boolean (gsettings, "show-countdown"); + g_object_unref (gsettings); + + if (show_countdown) + { + /* Ensure actions_box is visible for countdown */ + gtk_widget_show(windata->actions_box); + update_content_hbox_visibility(windata); + create_pie_countdown(windata); + } + } } void notification_tick(GtkWindow* nw, glong remaining) @@ -999,45 +1037,37 @@ paint_countdown (GtkWidget *pie, cairo_t* cr2; cairo_surface_t* surface; - context = gtk_widget_get_style_context (windata->win); - + // :selected { background-color:#aabbcc; } or + // .notification-box .countdown:selected { background-color:#aabbcc; } + context = gtk_widget_get_style_context (pie); gtk_style_context_save (context); gtk_style_context_set_state (context, GTK_STATE_FLAG_SELECTED); - get_background_color (context, GTK_STATE_FLAG_SELECTED, &bg); - gtk_style_context_restore (context); gtk_widget_get_allocation(pie, &alloc); - cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); surface = cairo_surface_create_similar (cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA, alloc.width, alloc.height); cr2 = cairo_create (surface); - - fill_background (pie, windata, cr2); - if (windata->timeout > 0) { gdouble pct = (gdouble) windata->remaining / (gdouble) windata->timeout; - gdk_cairo_set_source_rgba (cr2, &bg); - cairo_move_to (cr2, PIE_RADIUS, PIE_RADIUS); cairo_arc_negative (cr2, PIE_RADIUS, PIE_RADIUS, PIE_RADIUS, -G_PI_2, -(pct * G_PI * 2) - G_PI_2); cairo_line_to (cr2, PIE_RADIUS, PIE_RADIUS); cairo_fill (cr2); } - - cairo_destroy(cr2); + cairo_destroy (cr2); cairo_save (cr); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); cairo_restore (cr); - cairo_surface_destroy(surface); } @@ -1075,19 +1105,7 @@ void add_notification_action(GtkWindow* nw, const char* text, const char* key, A { gtk_widget_show(windata->actions_box); update_content_hbox_visibility(windata); - - /* Don't try to re-add a pie_countdown */ - if (!windata->pie_countdown) { - windata->pie_countdown = gtk_drawing_area_new(); - gtk_widget_set_halign (windata->pie_countdown, GTK_ALIGN_END); - gtk_widget_show(windata->pie_countdown); - - gtk_box_pack_end (GTK_BOX (windata->actions_box), windata->pie_countdown, FALSE, TRUE, 0); - gtk_widget_set_size_request(windata->pie_countdown, - PIE_WIDTH, PIE_HEIGHT); - g_signal_connect(G_OBJECT(windata->pie_countdown), "draw", - G_CALLBACK(on_countdown_draw), windata); - } + create_pie_countdown(windata); } if (windata->action_icons) { |
