[Xfce4-commits] [apps/xfce4-notifyd] 17/29: Correctly updating the theme for notification windows, setting the widget class to 'app-notification' and 'osd' so current user theme is selected.
noreply at xfce.org
noreply at xfce.org
Wed Jun 29 23:20:07 CEST 2016
This is an automated email from the git hooks/post-receive script.
ochosi pushed a commit to branch master
in repository apps/xfce4-notifyd.
commit 61480bcf48e458ce0543e6e98f4c5b4b36f7d607
Author: Ali Abdallah <aliovx at gmail.com>
Date: Fri Oct 16 08:47:33 2015 +0200
Correctly updating the theme for notification windows, setting
the widget class to 'app-notification' and 'osd' so current
user theme is selected.
Always use a small rounded corners. This should not be necessary in
theory, as Adwaita defined border-radius: 0 0 6px 6px; for the
app-notification and osd css classes. The problem is that Gtk
for some reason gets the border-radius as gint and not as GtkBorder.
Getting this way the first value only, which is 0.
---
xfce4-notifyd/xfce-notify-daemon.c | 70 ++++++++++++++++++++++++++++++--------
xfce4-notifyd/xfce-notify-window.c | 58 ++++++++++++++++---------------
2 files changed, 86 insertions(+), 42 deletions(-)
diff --git a/xfce4-notifyd/xfce-notify-daemon.c b/xfce4-notifyd/xfce-notify-daemon.c
index 3fb5c59..07d0998 100644
--- a/xfce4-notifyd/xfce-notify-daemon.c
+++ b/xfce4-notifyd/xfce-notify-daemon.c
@@ -949,7 +949,6 @@ notify_show_window (gpointer window)
return FALSE;
}
-
static void
add_and_propagate_css_provider (GtkWidget *widget, GtkStyleProvider *provider, guint priority)
{
@@ -968,6 +967,54 @@ add_and_propagate_css_provider (GtkWidget *widget, GtkStyleProvider *provider, g
}
}
+static void
+notify_update_theme_for_window (XfceNotifyDaemon *xndaemon, GtkWidget *window, gboolean redraw)
+{
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (GTK_WIDGET(window));
+
+ if (!xndaemon->is_default_theme)
+ {
+ if (gtk_style_context_has_class (context, "osd"))
+ gtk_style_context_remove_class (context, "osd");
+ if (gtk_style_context_has_class (context, "app-notification"))
+ gtk_style_context_remove_class (context, "app-notification");
+
+ add_and_propagate_css_provider (GTK_WIDGET(window),
+ GTK_STYLE_PROVIDER(xndaemon->css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
+ else
+ {
+ /* These classes are normally defined in themes */
+ if (!gtk_style_context_has_class (context, "osd"))
+ gtk_style_context_add_class (context, "osd");
+
+ if (!gtk_style_context_has_class (context, "app-notification"))
+ gtk_style_context_add_class (context, "app-notification");
+
+ /* Contains few style definition, use it as a fallback */
+ add_and_propagate_css_provider (GTK_WIDGET(window),
+ GTK_STYLE_PROVIDER(xndaemon->css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
+ }
+
+ if (redraw)
+ {
+ gtk_widget_reset_style (window);
+ gtk_widget_queue_draw (window);
+ }
+}
+
+static gboolean
+notify_update_theme_foreach (gpointer key, gpointer value, gpointer data)
+{
+ XfceNotifyDaemon *xndaemon = XFCE_NOTIFY_DAEMON(data);
+ GtkWidget *window = GTK_WIDGET(value);
+
+ notify_update_theme_for_window (xndaemon, window, TRUE);
+}
static gboolean notify_notify (XfceNotifyGBus *skeleton,
GDBusMethodInvocation *invocation,
@@ -1054,6 +1101,7 @@ static gboolean notify_notify (XfceNotifyGBus *skeleton,
OUT_id = replaces_id;
} else {
+ GtkStyleContext *context;
window = XFCE_NOTIFY_WINDOW(xfce_notify_window_new_with_actions(summary, body,
app_icon,
expire_timeout,
@@ -1079,19 +1127,8 @@ static gboolean notify_notify (XfceNotifyGBus *skeleton,
gtk_widget_realize(GTK_WIDGET(window));
- if (!xndaemon->is_default_theme)
- {
- add_and_propagate_css_provider (GTK_WIDGET(window),
- GTK_STYLE_PROVIDER(xndaemon->css_provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- }
- else
- {
- add_and_propagate_css_provider (GTK_WIDGET(window),
- GTK_STYLE_PROVIDER(xndaemon->css_provider),
- GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
- }
-
+ notify_update_theme_for_window (xndaemon, GTK_WIDGET(window), FALSE);
+
g_idle_add(notify_show_window, window);
}
@@ -1296,6 +1333,11 @@ xfce_notify_daemon_set_theme(XfceNotifyDaemon *xndaemon,
g_warning ("Faild to parse css file : %s\n", error->message);
g_error_free (error);
}
+ else
+ g_tree_foreach (xndaemon->active_notifications,
+ (GTraverseFunc)notify_update_theme_foreach,
+ xndaemon);
+
g_strfreev(files);
}
else
diff --git a/xfce4-notifyd/xfce-notify-window.c b/xfce4-notifyd/xfce-notify-window.c
index 6024a2d..686d4b1 100644
--- a/xfce4-notifyd/xfce-notify-window.c
+++ b/xfce4-notifyd/xfce-notify-window.c
@@ -359,33 +359,37 @@ xfce_notify_window_draw_rectangle (XfceNotifyWindow *window,
border_width = get_max_border_width (context, state);
border_padding = border_width / 2.0;
- if(radius < 1) {
- cairo_rectangle(cr, 0, 0, widget_allocation.width,
- widget_allocation.height);
- } else {
- cairo_move_to(cr, border_padding, radius + border_padding);
- cairo_arc(cr, radius + border_padding,
- radius + border_padding, radius,
- M_PI, 3.0*M_PI/2.0);
- cairo_line_to(cr,
- widget_allocation.width - radius - border_padding,
- border_padding);
- cairo_arc(cr,
- widget_allocation.width - radius - border_padding,
- radius + border_padding, radius,
- 3.0*M_PI/2.0, 0.0);
- cairo_line_to(cr, widget_allocation.width - border_padding,
- widget_allocation.height - radius - border_padding);
- cairo_arc(cr, widget_allocation.width - radius - border_padding,
- widget_allocation.height - radius - border_padding,
- radius, 0.0, M_PI/2.0);
- cairo_line_to(cr, radius + border_padding,
- widget_allocation.height - border_padding);
- cairo_arc(cr, radius + border_padding,
- widget_allocation.height - radius - border_padding,
- radius, M_PI/2.0, M_PI);
- cairo_close_path(cr);
+ /* Always use a small rounded corners. This should not be necessary in
+ * theory, as Adwaita defined border-radius: 0 0 6px 6px; for the
+ * app-notification and osd css classes. The problem is that Gtk for some
+ * reason gets the border-radius as gint and not as GtkBorder. Getting
+ * this way the first value only, which is 0. */
+ if ( radius == 0 ) {
+ radius = 6;
}
+
+ cairo_move_to(cr, border_padding, radius + border_padding);
+ cairo_arc(cr, radius + border_padding,
+ radius + border_padding, radius,
+ M_PI, 3.0*M_PI/2.0);
+ cairo_line_to(cr,
+ widget_allocation.width - radius - border_padding,
+ border_padding);
+ cairo_arc(cr,
+ widget_allocation.width - radius - border_padding,
+ radius + border_padding, radius,
+ 3.0*M_PI/2.0, 0.0);
+ cairo_line_to(cr, widget_allocation.width - border_padding,
+ widget_allocation.height - radius - border_padding);
+ cairo_arc(cr, widget_allocation.width - radius - border_padding,
+ widget_allocation.height - radius - border_padding,
+ radius, 0.0, M_PI/2.0);
+ cairo_line_to(cr, radius + border_padding,
+ widget_allocation.height - border_padding);
+ cairo_arc(cr, radius + border_padding,
+ widget_allocation.height - radius - border_padding,
+ radius, M_PI/2.0, M_PI);
+ cairo_close_path(cr);
}
static gboolean xfce_notify_window_draw (GtkWidget *widget,
@@ -395,7 +399,6 @@ static gboolean xfce_notify_window_draw (GtkWidget *widget,
GdkRGBA *border_color, *bg_color;
gint border_width;
GtkStateFlags state;
- double radius;
cairo_t *cr2;
cairo_surface_t *surface;
cairo_region_t *region;
@@ -431,7 +434,6 @@ static gboolean xfce_notify_window_draw (GtkWidget *widget,
state,
"border-color", &border_color,
"background-color", &bg_color,
- "border-radius", &radius,
NULL);
/* Draw the background, getting its color from the style context*/
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list