diff options
Diffstat (limited to 'src/themes/nodoka/nodoka-theme.c')
-rw-r--r-- | src/themes/nodoka/nodoka-theme.c | 135 |
1 files changed, 94 insertions, 41 deletions
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 */ |