Projects
Eulaceura:Mainline:GA
mate-notification-daemon
_service:obs_scm:0010-fix-theme-change-the-inde...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:0010-fix-theme-change-the-indent-of-kiran.c-and-add-notes.patch of Package mate-notification-daemon
From c35de938c793867a67d2297b209cc27805f9f527 Mon Sep 17 00:00:00 2001 From: yuanxing <yuanxing@kylinos.com.cn> Date: Thu, 28 Jan 2021 20:07:09 +0800 Subject: [PATCH 9/9] fix(theme):change the indent of kiran.c and add notes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改kiran.c的缩进并且添加注释 --- src/daemon/daemon.c | 7 +- src/themes/kiran/kiran.c | 701 ++++++++++++++++++++------------------- 2 files changed, 365 insertions(+), 343 deletions(-) diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 3ee2266..44572e3 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -1351,7 +1351,12 @@ static gboolean notify_daemon_notify_handler(NotifyDaemonNotifications *object, { theme_clear_notification_actions (nw); } - + + /* + * Change the order of the following two statements: + * First set the message hints, then set the message content. + * If summary is not set, summary can be set according to hints + */ theme_set_notification_hints (nw, hints); theme_set_notification_text (nw, summary, body); diff --git a/src/themes/kiran/kiran.c b/src/themes/kiran/kiran.c index 7858d52..732cb2e 100644 --- a/src/themes/kiran/kiran.c +++ b/src/themes/kiran/kiran.c @@ -1,25 +1,7 @@ /* * kiran.c - * This file is part of notification-daemon-engine-kiran - * - * Copyright (C) 2012 - Stefano Karapetsas <stefano@karapetsas.com> - * Copyright (C) 2010 - Eduardo Grajeda - * Copyright (C) 2008 - Martin Sourada - * - * notification-daemon-engine-kiran is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 3 of the License, - * or (at your option) any later version. - * - * notification-daemon-engine-kiran is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with notification-daemon-engine-kiran; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA + * A theme of notification + * Copyright ©2020 KylinSec. All rights reserved. */ #include "config.h" @@ -67,7 +49,6 @@ typedef struct GtkTextDirection rtl; } WindowData; - enum { URGENCY_LOW, @@ -76,45 +57,45 @@ enum }; gboolean theme_check_init(unsigned int major_ver, unsigned int minor_ver, - unsigned int micro_ver); + unsigned int micro_ver); void get_theme_info(char **theme_name, char **theme_ver, char **author, - char **homepage); -GtkWindow* create_notification(UrlClickedCb url_clicked); + char **homepage); +GtkWindow *create_notification(UrlClickedCb url_clicked); void set_notification_text(GtkWindow *nw, const char *summary, - const char *body); + const char *body); void set_notification_icon(GtkWindow *nw, GdkPixbuf *pixbuf); void set_notification_arrow(GtkWidget *nw, gboolean visible, int x, int y); void add_notification_action(GtkWindow *nw, const char *text, const char *key, - ActionInvokedCb cb); + ActionInvokedCb cb); void clear_notification_actions(GtkWindow *nw); 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); -#define STRIPE_WIDTH 32 -#define WIDTH 380 -#define IMAGE_SIZE 48 +#define STRIPE_WIDTH 32 +#define WIDTH 380 +#define IMAGE_SIZE 48 #define IMAGE_PADDING 12 -#define SPACER_LEFT 30 -#define PIE_RADIUS 7 -#define PIE_WIDTH (2 * PIE_RADIUS) -#define PIE_HEIGHT (2 * PIE_RADIUS) +#define SPACER_LEFT 30 +#define PIE_RADIUS 7 +#define PIE_WIDTH (2 * PIE_RADIUS) +#define PIE_HEIGHT (2 * PIE_RADIUS) #define BODY_X_OFFSET (IMAGE_SIZE + 24) -#define DEFAULT_ARROW_OFFSET (SPACER_LEFT + 12) -#define DEFAULT_ARROW_HEIGHT 14 -#define DEFAULT_ARROW_WIDTH 22 -#define DEFAULT_ARROW_SKEW -6 -#define BACKGROUND_OPACITY 1.0 +#define DEFAULT_ARROW_OFFSET (SPACER_LEFT + 12) +#define DEFAULT_ARROW_HEIGHT 14 +#define DEFAULT_ARROW_WIDTH 22 +#define DEFAULT_ARROW_SKEW -6 +#define BACKGROUND_OPACITY 1.0 #define GRADIENT_CENTER 0.7 /* Support Nodoka Functions */ /* Handle clicking on link */ static gboolean -activate_link (GtkLabel *label, const char *url, WindowData *windata) +activate_link(GtkLabel *label, const char *url, WindowData *windata) { - windata->url_clicked (GTK_WINDOW (windata->win), url); + windata->url_clicked(GTK_WINDOW(windata->win), url); return TRUE; } @@ -127,15 +108,18 @@ destroy_windata(WindowData *windata) /* Draw fuctions */ /* Standard rounded rectangle */ static void -rounded_rectangle (cairo_t * cr, - double x, double y, double w, double h, - int radius) +rounded_rectangle(cairo_t *cr, + double x, + double y, + double w, + double h, + int radius) { - cairo_move_to (cr, x + radius, y); - cairo_arc (cr, x + w - radius, y + radius, radius, G_PI * 1.5, G_PI * 2); - cairo_arc (cr, x + w - radius, y + h - radius, radius, 0, G_PI * 0.5); - cairo_arc (cr, x + radius, y + h - radius, radius, G_PI * 0.5, G_PI); - cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI * 1.5); + cairo_move_to(cr, x + radius, y); + cairo_arc(cr, x + w - radius, y + radius, radius, G_PI * 1.5, G_PI * 2); + cairo_arc(cr, x + w - radius, y + h - radius, radius, 0, G_PI * 0.5); + cairo_arc(cr, x + radius, y + h - radius, radius, G_PI * 0.5, G_PI); + cairo_arc(cr, x + radius, y + radius, radius, G_PI, G_PI * 1.5); } /* Fill background */ @@ -149,23 +133,33 @@ fill_background(GtkWidget *widget, WindowData *windata, cairo_t *cr) alpha = 1.0; cairo_pattern_t *pattern; - pattern = cairo_pattern_create_linear (0, 0, 0, windata->height); - cairo_pattern_add_color_stop_rgba (pattern, 0, - 34/255.0, 34/255.0, 34/255.0, alpha); - cairo_pattern_add_color_stop_rgba (pattern, GRADIENT_CENTER, - 34/255.0, 34/255.0, 34/255.0, alpha); - cairo_pattern_add_color_stop_rgba (pattern, 1, - 34/255.0, 34/255.0, 34/255.0, alpha); - cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); - - rounded_rectangle (cr, 0, 0, windata->width, - windata->height, 8); - - cairo_fill (cr); + pattern = cairo_pattern_create_linear(0, 0, 0, windata->height); + cairo_pattern_add_color_stop_rgba(pattern, + 0, + 34 / 255.0, + 34 / 255.0, + 34 / 255.0, + alpha); + cairo_pattern_add_color_stop_rgba(pattern, + GRADIENT_CENTER, + 34 / 255.0, + 34 / 255.0, + 34 / 255.0, + alpha); + cairo_pattern_add_color_stop_rgba(pattern, + 1, + 34 / 255.0, + 34 / 255.0, + 34 / 255.0, + alpha); + cairo_set_source(cr, pattern); + cairo_pattern_destroy(pattern); + + rounded_rectangle(cr, 0, 0, windata->width, windata->height, 8); + + cairo_fill(cr); } - /** * @brief 当鼠标进入消息框窗体时,重绘背景 */ @@ -179,20 +173,31 @@ fill_background_when_pointer_enter(GtkWidget *widget, WindowData *windata, cairo alpha = 1.0; cairo_pattern_t *pattern; - pattern = cairo_pattern_create_linear (0, 0, 0, windata->height); - cairo_pattern_add_color_stop_rgba (pattern, 0, - 51/255.0, 51/255.0, 51/255.0, alpha); - cairo_pattern_add_color_stop_rgba (pattern, GRADIENT_CENTER, - 51/255.0, 51/255.0, 51/255.0, alpha); - cairo_pattern_add_color_stop_rgba (pattern, 1, - 51/255.0, 51/255.0, 51/255.0, alpha); - cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); - - rounded_rectangle (cr, 0, 0, windata->width, - windata->height, 8); - - cairo_fill (cr); + pattern = cairo_pattern_create_linear(0, 0, 0, windata->height); + cairo_pattern_add_color_stop_rgba(pattern, + 0, + 51 / 255.0, + 51 / 255.0, + 51 / 255.0, + alpha); + cairo_pattern_add_color_stop_rgba(pattern, + GRADIENT_CENTER, + 51 / 255.0, + 51 / 255.0, + 51 / 255.0, + alpha); + cairo_pattern_add_color_stop_rgba(pattern, + 1, + 51 / 255.0, + 51 / 255.0, + 51 / 255.0, + alpha); + cairo_set_source(cr, pattern); + cairo_pattern_destroy(pattern); + + rounded_rectangle(cr, 0, 0, windata->width, windata->height, 8); + + cairo_fill(cr); } static void @@ -202,18 +207,23 @@ 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, 92/255.0, 92/255.0, 92/255.0, 1); + cairo_set_source_rgba(cr, + 92 / 255.0, + 92 / 255.0, + 92 / 255.0, 1); 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); + cairo_arc_negative(cr, + PIE_RADIUS, PIE_RADIUS, + PIE_RADIUS, + -G_PI / 2, (-0.25 + arc_angle) * 2 * G_PI); cairo_line_to(cr, PIE_RADIUS, PIE_RADIUS); - - cairo_fill (cr); + + cairo_fill(cr); } static void -update_shape_region (cairo_surface_t *surface, - WindowData *windata) +update_shape_region(cairo_surface_t *surface, + WindowData *windata) { if (windata->width == windata->last_width && windata->height == windata->last_height) { @@ -223,20 +233,23 @@ update_shape_region (cairo_surface_t *surface, if (windata->width == 0 || windata->height == 0) { GtkAllocation allocation; - gtk_widget_get_allocation (windata->win, &allocation); + gtk_widget_get_allocation(windata->win, &allocation); - windata->width = MAX (allocation.width, 1); - windata->height = MAX (allocation.height, 1); + windata->width = MAX(allocation.width, 1); + windata->height = MAX(allocation.height, 1); } - if (!windata->composited) { + if (!windata->composited) + { cairo_region_t *region; - region = gdk_cairo_region_create_from_surface (surface); - gtk_widget_shape_combine_region (windata->win, region); - cairo_region_destroy (region); - } else { - gtk_widget_shape_combine_region (windata->win, NULL); + region = gdk_cairo_region_create_from_surface(surface); + gtk_widget_shape_combine_region(windata->win, region); + cairo_region_destroy(region); + } + else + { + gtk_widget_shape_combine_region(windata->win, NULL); return; } @@ -245,14 +258,15 @@ update_shape_region (cairo_surface_t *surface, } static void -paint_window (GtkWidget *widget, - cairo_t *cr, - WindowData *windata) +paint_window(GtkWidget *widget, + cairo_t *cr, + WindowData *windata) { cairo_surface_t *surface; cairo_t *cr2; - if (windata->width == 0 || windata->height == 0) { + if (windata->width == 0 || windata->height == 0) + { GtkAllocation allocation; gtk_widget_get_allocation(windata->win, &allocation); @@ -260,41 +274,39 @@ paint_window (GtkWidget *widget, windata->height = allocation.height; } - surface = cairo_surface_create_similar(cairo_get_target(cr), - CAIRO_CONTENT_COLOR_ALPHA, - windata->width, - windata->height); + surface = cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA, windata->width, windata->height); - cr2 = cairo_create (surface); + cr2 = cairo_create(surface); fill_background(widget, windata, cr2); - cairo_fill (cr2); + cairo_fill(cr2); + + cairo_destroy(cr2); - cairo_destroy (cr2); + cairo_save(cr); - cairo_save (cr); - - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - cairo_set_source_surface (cr, surface, 0, 0); - cairo_paint (cr); - cairo_restore (cr); + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_surface(cr, surface, 0, 0); + cairo_paint(cr); + cairo_restore(cr); - update_shape_region (surface, windata); + update_shape_region(surface, windata); - cairo_surface_destroy (surface); + cairo_surface_destroy(surface); } /** * @brief 当鼠标进入消息框窗体时,给窗体加上边框 */ static void -paint_window_when_pointer_enter(GtkWidget *widget, - cairo_t *cr, - WindowData *windata) +paint_window_when_pointer_enter(GtkWidget *widget, + cairo_t *cr, + WindowData *windata) { cairo_surface_t *surface; cairo_t *cr2; - if (windata->width == 0 || windata->height == 0) { + if (windata->width == 0 || windata->height == 0) + { GtkAllocation allocation; gtk_widget_get_allocation(windata->win, &allocation); @@ -302,34 +314,34 @@ paint_window_when_pointer_enter(GtkWidget *widget, windata->height = allocation.height; } - surface = cairo_surface_create_similar(cairo_get_target(cr), - CAIRO_CONTENT_COLOR_ALPHA, - windata->width, - windata->height); + surface = cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA, windata->width, windata->height); - cr2 = cairo_create (surface); + cr2 = cairo_create(surface); fill_background_when_pointer_enter(widget, windata, cr2); - cairo_fill (cr2); - - rounded_rectangle (cr2, 0, 0, windata->width , windata->height, 8); - cairo_set_source_rgba (cr2, 40/255.0, 144/255.0, 216/255.0, 1.0); - cairo_set_line_width (cr2, 4.0); - cairo_stroke (cr2); + cairo_fill(cr2); - cairo_destroy (cr2); + rounded_rectangle(cr2, 0, 0, windata->width, windata->height, 8); + cairo_set_source_rgba(cr2, + 40 / 255.0, + 144 / 255.0, + 216 / 255.0, + 1.0); + cairo_set_line_width(cr2, 4.0); + cairo_stroke(cr2); - cairo_save (cr); - - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - cairo_set_source_surface (cr, surface, 0, 0); - cairo_paint (cr); - cairo_restore (cr); + cairo_destroy(cr2); - update_shape_region (surface, windata); + cairo_save(cr); - cairo_surface_destroy (surface); + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_surface(cr, surface, 0, 0); + cairo_paint(cr); + cairo_restore(cr); + update_shape_region(surface, windata); + + cairo_surface_destroy(surface); } /* Event handlers */ @@ -337,16 +349,16 @@ paint_window_when_pointer_enter(GtkWidget *widget, * @brief "draw"回调函数:根据窗体当前状态,判断绘制成鼠标移入样式 */ static gboolean -on_draw (GtkWidget *widget, cairo_t *cr, WindowData *windata) +on_draw(GtkWidget *widget, cairo_t *cr, WindowData *windata) { GtkStateFlags flags = gtk_widget_get_state_flags(windata->win); if (flags & GTK_STATE_FLAG_PRELIGHT) { - paint_window_when_pointer_enter(widget , cr , windata); + paint_window_when_pointer_enter(widget, cr, windata); } else { - paint_window (widget, cr, windata); + paint_window(widget, cr, windata); } return FALSE; } @@ -360,111 +372,116 @@ countdown_expose_cb(GtkWidget *pie, cairo_surface_t *surface; GtkAllocation alloc; - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - gtk_widget_get_allocation (pie, &alloc); + 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); + cr2 = cairo_create(surface); - cairo_translate (cr2, -alloc.x, -alloc.y); + cairo_translate(cr2, -alloc.x, -alloc.y); GtkStateFlags flags = gtk_widget_get_state_flags(windata->win); if (flags & GTK_STATE_FLAG_PRELIGHT) { - fill_background_when_pointer_enter(pie, windata ,cr2); + fill_background_when_pointer_enter(pie, windata, cr2); } else { - fill_background (pie, windata, cr2); + fill_background(pie, windata, cr2); } - cairo_translate (cr2, alloc.x, alloc.y); - draw_pie (pie, windata, cr2); - cairo_fill (cr2); + cairo_translate(cr2, alloc.x, alloc.y); + draw_pie(pie, windata, cr2); + 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_save(cr); + cairo_set_source_surface(cr, surface, 0, 0); + cairo_paint(cr); + cairo_restore(cr); - cairo_surface_destroy (surface); + cairo_surface_destroy(surface); return TRUE; } -static gboolean on_configure_event (GtkWidget* widget, GdkEventConfigure* event, WindowData* windata) +static gboolean +on_configure_event(GtkWidget *widget, GdkEventConfigure *event, WindowData *windata) { windata->width = event->width; windata->height = event->height; - gtk_widget_queue_draw (widget); + gtk_widget_queue_draw(widget); return FALSE; } -static void on_composited_changed (GtkWidget* window, WindowData* windata) +static void +on_composited_changed(GtkWidget *window, WindowData *windata) { - windata->composited = gdk_screen_is_composited (gtk_widget_get_screen(window)); + windata->composited = gdk_screen_is_composited(gtk_widget_get_screen(window)); - gtk_widget_queue_draw (window); + gtk_widget_queue_draw(window); } - /** * @brief 事件过滤:当鼠标移入或者离开消息框,绘制相应的消息框状态 */ -GdkFilterReturn event_filter(GdkXEvent *xevent, GdkEvent *event, gpointer userdata) +GdkFilterReturn +event_filter(GdkXEvent *xevent, GdkEvent *event, gpointer userdata) { - XEvent *x_event = (XEvent*)xevent; - XGenericEvent *general_event = (XGenericEvent*)x_event; + XEvent *x_event = (XEvent *)xevent; + XGenericEvent *general_event = (XGenericEvent *)x_event; GtkWidget *window = GTK_WIDGET(userdata); - switch(x_event->type) { - case EnterNotify: - gtk_widget_set_state_flags(window, GTK_STATE_FLAG_PRELIGHT, FALSE); - gtk_widget_queue_draw(window); - break; - case LeaveNotify: - gtk_widget_set_state_flags(window, gtk_widget_get_state_flags(window) & ~GTK_STATE_FLAG_PRELIGHT, TRUE); - gtk_widget_queue_draw(window); - break; - case GenericEvent: - do + switch (x_event->type) + { + case EnterNotify: + gtk_widget_set_state_flags(window, GTK_STATE_FLAG_PRELIGHT, FALSE); + gtk_widget_queue_draw(window); + break; + case LeaveNotify: + gtk_widget_set_state_flags(window, gtk_widget_get_state_flags(window) & ~GTK_STATE_FLAG_PRELIGHT, TRUE); + gtk_widget_queue_draw(window); + break; + case GenericEvent: + do + { + if (general_event->evtype == EnterNotify) + { + gtk_widget_set_state_flags(window, GTK_STATE_FLAG_PRELIGHT, FALSE); + gtk_widget_queue_draw(window); + } + + if (general_event->evtype == LeaveNotify) { - if (general_event->evtype == EnterNotify) { - gtk_widget_set_state_flags(window, GTK_STATE_FLAG_PRELIGHT, FALSE); - gtk_widget_queue_draw(window); - } - - if (general_event->evtype == LeaveNotify) { - gtk_widget_set_state_flags(window, gtk_widget_get_state_flags(window) & ~GTK_STATE_FLAG_PRELIGHT, TRUE); - gtk_widget_queue_draw(window); - } - }while(0); - break; - default: - break; + gtk_widget_set_state_flags(window, gtk_widget_get_state_flags(window) & ~GTK_STATE_FLAG_PRELIGHT, TRUE); + gtk_widget_queue_draw(window); + } + } while (0); + break; + default: + break; } return GDK_FILTER_CONTINUE; } static void -on_realize(GtkWidget *widget , gpointer userdata ) +on_realize(GtkWidget *widget, gpointer userdata) { GdkWindow *window = gtk_widget_get_window(widget); gdk_window_add_filter(window, event_filter, widget); } - static void -action_clicked_cb(GtkWidget *w, GdkEventButton *event, +action_clicked_cb(GtkWidget *w, + GdkEventButton *event, ActionInvokedCb action_cb) { - GtkWindow *nw = g_object_get_data(G_OBJECT(w), "_nw"); + GtkWindow *nw = g_object_get_data(G_OBJECT(w), "_nw"); const char *key = g_object_get_data(G_OBJECT(w), "_action_key"); action_cb(nw, key); @@ -474,51 +491,48 @@ action_clicked_cb(GtkWidget *w, GdkEventButton *event, /* Checking if we support this notification daemon version */ gboolean -theme_check_init(unsigned int major_ver, unsigned int minor_ver, +theme_check_init(unsigned int major_ver, + unsigned int minor_ver, unsigned int micro_ver) { return major_ver == NOTIFICATION_DAEMON_MAJOR_VERSION && minor_ver == NOTIFICATION_DAEMON_MINOR_VERSION && micro_ver == NOTIFICATION_DAEMON_MICRO_VERSION; } /* Sending theme info to the notification daemon */ -void -get_theme_info(char **theme_name, - char **theme_ver, - char **author, - char **homepage) +void get_theme_info(char **theme_name, + char **theme_ver, + char **author, + char **homepage) { *theme_name = g_strdup("Kiran"); - *theme_ver = g_strdup_printf("%d.%d.%d", NOTIFICATION_DAEMON_MAJOR_VERSION, - NOTIFICATION_DAEMON_MINOR_VERSION, - NOTIFICATION_DAEMON_MICRO_VERSION); + *theme_ver = g_strdup_printf("%d.%d.%d", NOTIFICATION_DAEMON_MAJOR_VERSION, NOTIFICATION_DAEMON_MINOR_VERSION, NOTIFICATION_DAEMON_MICRO_VERSION); *author = g_strdup("Eduardo Grajeda"); *homepage = g_strdup("http://github.com/tatofoo/"); } - + /* set css*/ -static void -set_css(GtkWidget* widget) +static void +set_css(GtkWidget *widget) { - GtkCssProvider *provider = gtk_css_provider_new (); + GtkCssProvider *provider = gtk_css_provider_new(); - gtk_css_provider_load_from_resource (provider, "/kiran/themes/kiran.css"); - gtk_style_context_add_provider_for_screen (gtk_widget_get_screen(widget), - GTK_STYLE_PROVIDER(provider), - GTK_STYLE_PROVIDER_PRIORITY_USER); + gtk_css_provider_load_from_resource(provider, "/kiran/themes/kiran.css"); + gtk_style_context_add_provider_for_screen(gtk_widget_get_screen(widget), + GTK_STYLE_PROVIDER(provider), + GTK_STYLE_PROVIDER_PRIORITY_USER); gtk_style_context_reset_widgets(gtk_widget_get_screen(widget)); - g_object_unref (provider); + g_object_unref(provider); } - /* Create new notification */ GtkWindow * create_notification(UrlClickedCb url_clicked) { GtkWidget *win; GtkWidget *main_vbox; - GtkWidget* close_button; - GtkWidget* action_vbox; + GtkWidget *close_button; + GtkWidget *action_vbox; GtkWidget *vbox; AtkObject *atkobj; WindowData *windata; @@ -532,16 +546,16 @@ create_notification(UrlClickedCb url_clicked) win = gtk_window_new(GTK_WINDOW_POPUP); gtk_window_set_resizable(GTK_WINDOW(win), FALSE); - gtk_window_set_decorated (GTK_WINDOW(win), TRUE); + gtk_window_set_decorated(GTK_WINDOW(win), TRUE); windata->win = win; - + //register resource resource = kiran_get_resource(); - g_resources_register (resource); + g_resources_register(resource); set_css(windata->win); - gtk_widget_set_name(windata->win , "notification_window"); - gtk_widget_set_size_request(windata->win , WIDTH,70); + gtk_widget_set_name(windata->win, "notification_window"); + gtk_widget_set_size_request(windata->win, WIDTH, 70); windata->rtl = gtk_widget_get_default_direction(); windata->composited = FALSE; screen = gtk_window_get_screen(GTK_WINDOW(win)); @@ -556,9 +570,9 @@ create_notification(UrlClickedCb url_clicked) gtk_window_set_title(GTK_WINDOW(win), "Notification"); gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_NOTIFICATION); gtk_widget_add_events(win, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); - - g_signal_connect(G_OBJECT(win), "realize" , G_CALLBACK(on_realize) , NULL); - + + g_signal_connect(G_OBJECT(win), "realize", G_CALLBACK(on_realize), NULL); + gtk_widget_realize(win); g_object_set_data_full(G_OBJECT(win), "windata", windata, @@ -566,142 +580,142 @@ create_notification(UrlClickedCb url_clicked) atk_object_set_role(gtk_widget_get_accessible(win), ATK_ROLE_ALERT); main_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_set_name(main_vbox , "main_vbox"); + gtk_widget_set_name(main_vbox, "main_vbox"); gtk_widget_show(main_vbox); - gtk_container_add (GTK_CONTAINER (win), main_vbox); + gtk_container_add(GTK_CONTAINER(win), main_vbox); + + g_signal_connect(G_OBJECT(main_vbox), "draw", G_CALLBACK(on_draw), windata); - g_signal_connect (G_OBJECT (main_vbox), "draw", - G_CALLBACK (on_draw), windata); + g_signal_connect(G_OBJECT(win), "configure-event", G_CALLBACK(on_configure_event), windata); - g_signal_connect (G_OBJECT (win), "configure-event", G_CALLBACK (on_configure_event), windata); + g_signal_connect(G_OBJECT(win), "composited-changed", G_CALLBACK(on_composited_changed), windata); - g_signal_connect (G_OBJECT (win), "composited-changed", G_CALLBACK (on_composited_changed), windata); + windata->main_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_set_name(windata->main_hbox, "main_hbox"); + gtk_widget_set_halign(windata->main_hbox, GTK_ALIGN_FILL); + gtk_widget_set_valign(windata->main_hbox, GTK_ALIGN_START); + gtk_widget_show(windata->main_hbox); + gtk_box_pack_start(GTK_BOX(main_vbox), windata->main_hbox, + TRUE, TRUE, 0); - windata->main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_widget_set_name(windata->main_hbox , "main_hbox"); - gtk_widget_set_halign (windata->main_hbox, GTK_ALIGN_FILL); - gtk_widget_set_valign (windata->main_hbox, GTK_ALIGN_START); - gtk_widget_show (windata->main_hbox); - gtk_box_pack_start (GTK_BOX(main_vbox), windata->main_hbox, TRUE, TRUE, 0); - - /* The icon goes at the left */ + /* The icon goes at the left */ windata->iconbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_set_name(windata->iconbox , "icon_box"); + gtk_widget_set_name(windata->iconbox, "icon_box"); gtk_widget_show(windata->iconbox); gtk_box_pack_start(GTK_BOX(windata->main_hbox), windata->iconbox, FALSE, FALSE, 0); - gtk_widget_set_valign (GTK_WIDGET(windata->iconbox),GTK_ALIGN_START); - + gtk_widget_set_valign(GTK_WIDGET(windata->iconbox), GTK_ALIGN_START); + windata->icon = gtk_image_new(); gtk_box_pack_start(GTK_BOX(windata->iconbox), windata->icon, FALSE, FALSE, 0); - /* The title and the text at the right */ - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_set_name(vbox , "text_vbox"); - gtk_widget_set_halign (vbox, GTK_ALIGN_FILL); - gtk_widget_show (vbox); - gtk_box_pack_start (GTK_BOX (windata->main_hbox), vbox, TRUE, TRUE, 0); - gtk_widget_set_hexpand (vbox, TRUE); - + /* The title and the text at the right */ + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + gtk_widget_set_name(vbox, "text_vbox"); + gtk_widget_set_halign(vbox, GTK_ALIGN_FILL); + gtk_widget_show(vbox); + gtk_box_pack_start(GTK_BOX(windata->main_hbox), vbox, + TRUE, TRUE, 0); + gtk_widget_set_hexpand(vbox, TRUE); /* Add action_vbox*/ - action_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL , 0); - gtk_widget_set_name(action_vbox , "action_vbox"); + action_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + gtk_widget_set_name(action_vbox, "action_vbox"); gtk_widget_show(action_vbox); - gtk_box_pack_end(GTK_BOX(windata->main_hbox), action_vbox , FALSE , FALSE ,0); - gtk_widget_set_halign (action_vbox, GTK_ALIGN_END); + gtk_box_pack_end(GTK_BOX(windata->main_hbox), action_vbox, + FALSE, FALSE, 0); + gtk_widget_set_halign(action_vbox, GTK_ALIGN_END); - /* Add the close button */ + /* Add the close button */ close_button = gtk_button_new(); - gtk_widget_set_name(GTK_WIDGET(close_button) ,"close_button" ); - gtk_widget_set_size_request(GTK_WIDGET(close_button) , 16 , 16); - gtk_widget_set_valign (close_button, GTK_ALIGN_START); - gtk_widget_set_halign (close_button, GTK_ALIGN_END); - gtk_widget_set_vexpand (close_button,FALSE); - gtk_widget_set_hexpand(close_button , FALSE); + gtk_widget_set_name(GTK_WIDGET(close_button), "close_button"); + gtk_widget_set_size_request(GTK_WIDGET(close_button), 16, 16); + gtk_widget_set_valign(close_button, GTK_ALIGN_START); + gtk_widget_set_halign(close_button, GTK_ALIGN_END); + gtk_widget_set_vexpand(close_button, FALSE); + gtk_widget_set_hexpand(close_button, FALSE); gtk_widget_show(close_button); windata->close_button = close_button; - gtk_box_pack_start (GTK_BOX (action_vbox), - windata->close_button, - FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(action_vbox), windata->close_button, + FALSE, FALSE, 0); gtk_button_set_relief(GTK_BUTTON(close_button), GTK_RELIEF_NONE); gtk_container_set_border_width(GTK_CONTAINER(close_button), 0); g_signal_connect_swapped(G_OBJECT(close_button), "clicked", G_CALLBACK(gtk_widget_destroy), win); atkobj = gtk_widget_get_accessible(close_button); - atk_action_set_description(ATK_ACTION(atkobj), 0, - _("Closes the notification.")); + atk_action_set_description(ATK_ACTION(atkobj), 0, _("Closes the notification.")); atk_object_set_name(atkobj, ""); - atk_object_set_description (atkobj, _("Closes the notification.")); + atk_object_set_description(atkobj, _("Closes the notification.")); - windata->actions_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,10); - gtk_widget_set_name(windata->actions_box , "actions_box"); + windata->actions_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10); + gtk_widget_set_name(windata->actions_box, "actions_box"); gtk_widget_set_halign(windata->actions_box, GTK_ALIGN_END); gtk_widget_show(windata->actions_box); gtk_box_pack_end(GTK_BOX(action_vbox), windata->actions_box, FALSE, FALSE, 0); - gtk_widget_set_vexpand (windata->actions_box,FALSE); - gtk_widget_set_hexpand (windata->actions_box,FALSE); + gtk_widget_set_vexpand(windata->actions_box, FALSE); + gtk_widget_set_hexpand(windata->actions_box, FALSE); windata->summary_label = gtk_label_new(NULL); gtk_widget_set_name(windata->summary_label, "summary_label"); gtk_widget_show(windata->summary_label); - gtk_box_pack_start(GTK_BOX(vbox), windata->summary_label, FALSE, FALSE, 0); - gtk_label_set_xalign (GTK_LABEL (windata->summary_label), 0.0); - gtk_label_set_yalign (GTK_LABEL (windata->summary_label), 0.0); + gtk_box_pack_start(GTK_BOX(vbox), windata->summary_label, + FALSE, FALSE, 0); + gtk_label_set_xalign(GTK_LABEL(windata->summary_label), 0.0); + gtk_label_set_yalign(GTK_LABEL(windata->summary_label), 0.0); gtk_label_set_line_wrap(GTK_LABEL(windata->summary_label), TRUE); - gtk_label_set_line_wrap_mode (GTK_LABEL (windata->summary_label), PANGO_WRAP_WORD_CHAR); + gtk_label_set_line_wrap_mode(GTK_LABEL(windata->summary_label), PANGO_WRAP_WORD_CHAR); atkobj = gtk_widget_get_accessible(windata->summary_label); - atk_object_set_description (atkobj, _("Notification summary text.")); + atk_object_set_description(atkobj, _("Notification summary text.")); windata->body_label = gtk_label_new(NULL); - gtk_widget_set_name(windata->body_label , "body_label"); - gtk_box_pack_start(GTK_BOX(vbox), windata->body_label, FALSE, FALSE, 0); - gtk_label_set_xalign (GTK_LABEL (windata->body_label), 0.0); - gtk_label_set_yalign (GTK_LABEL (windata->body_label), 0.0); + gtk_widget_set_name(windata->body_label, "body_label"); + gtk_box_pack_start(GTK_BOX(vbox), windata->body_label, + FALSE, FALSE, 0); + gtk_label_set_xalign(GTK_LABEL(windata->body_label), 0.0); + gtk_label_set_yalign(GTK_LABEL(windata->body_label), 0.0); gtk_label_set_line_wrap(GTK_LABEL(windata->body_label), TRUE); - gtk_label_set_line_wrap_mode (GTK_LABEL (windata->body_label), PANGO_WRAP_WORD_CHAR); - gtk_label_set_max_width_chars (GTK_LABEL (windata->body_label), 50); - gtk_widget_set_vexpand (windata->body_label, TRUE); + gtk_label_set_line_wrap_mode(GTK_LABEL(windata->body_label), PANGO_WRAP_WORD_CHAR); + gtk_label_set_max_width_chars(GTK_LABEL(windata->body_label), 50); + gtk_widget_set_vexpand(windata->body_label, TRUE); g_signal_connect(G_OBJECT(windata->body_label), "activate-link", - G_CALLBACK(activate_link), windata); + G_CALLBACK(activate_link), windata); atkobj = gtk_widget_get_accessible(windata->body_label); - atk_object_set_description (atkobj, _("Notification body text.")); + atk_object_set_description(atkobj, _("Notification body text.")); - g_resources_unregister (resource); + g_resources_unregister(resource); return GTK_WINDOW(win); } /* Set the notification text */ -void -set_notification_text(GtkWindow *nw, const char *summary, const char *body) +void set_notification_text(GtkWindow *nw, const char *summary, const char *body) { WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata"); g_assert(windata != NULL); - if(summary == NULL || *summary == '\0') + if (summary == NULL || *summary == '\0') { - if(windata->urgency == URGENCY_CRITICAL) + if (windata->urgency == URGENCY_CRITICAL) { summary = _("Normal Notification"); } - else if(windata->urgency == URGENCY_LOW) + else if (windata->urgency == URGENCY_LOW) { summary = _("Low Notification"); } - else if(windata->urgency == URGENCY_CRITICAL) + else if (windata->urgency == URGENCY_CRITICAL) { summary = _("Critical Notification"); } } - - gtk_label_set_text(GTK_LABEL(windata->summary_label) , summary); - gtk_label_set_text (GTK_LABEL (windata->body_label), body); + + gtk_label_set_text(GTK_LABEL(windata->summary_label), summary); + gtk_label_set_text(GTK_LABEL(windata->body_label), body); if (body == NULL || *body == '\0') gtk_widget_hide(windata->body_label); @@ -710,15 +724,14 @@ set_notification_text(GtkWindow *nw, const char *summary, const char *body) gtk_widget_set_size_request( ((body != NULL && *body != '\0') - ? windata->body_label : windata->summary_label), - WIDTH - (IMAGE_SIZE + IMAGE_PADDING*2) -80, + ? windata->body_label + : windata->summary_label), + WIDTH - (IMAGE_SIZE + IMAGE_PADDING * 2) - 80, -1); - } /* Set notification icon */ -void -set_notification_icon(GtkWindow *nw, GdkPixbuf *pixbuf) +void set_notification_icon(GtkWindow *nw, GdkPixbuf *pixbuf) { WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata"); g_assert(windata != NULL); @@ -729,8 +742,7 @@ set_notification_icon(GtkWindow *nw, GdkPixbuf *pixbuf) int pixbuf_width = gdk_pixbuf_get_width(pixbuf); gtk_widget_show(windata->icon); - gtk_widget_set_size_request(windata->iconbox, - MAX(BODY_X_OFFSET, pixbuf_width), -1); + gtk_widget_set_size_request(windata->iconbox, MAX(BODY_X_OFFSET, pixbuf_width), -1); } else { @@ -740,16 +752,16 @@ set_notification_icon(GtkWindow *nw, GdkPixbuf *pixbuf) } /* Set notification arrow */ -void -set_notification_arrow(GtkWidget *nw, gboolean visible, int x, int y) +void set_notification_arrow(GtkWidget *nw, gboolean visible, int x, int y) { - /* nothing */ + /* nothing */ } /* Add notification action */ -void -add_notification_action(GtkWindow *nw, const char *text, const char *key, - ActionInvokedCb cb) +void add_notification_action(GtkWindow *nw, + const char *text, + const char *key, + ActionInvokedCb cb) { WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata"); GtkWidget *label; @@ -759,26 +771,27 @@ add_notification_action(GtkWindow *nw, const char *text, const char *key, char *buf; g_assert(windata != NULL); - + 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) { + 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_END); + gtk_widget_set_halign(windata->pie_countdown, GTK_ALIGN_END); + gtk_widget_set_valign(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, FALSE, 0); - gtk_widget_set_size_request(windata->pie_countdown, - PIE_WIDTH, PIE_HEIGHT); + gtk_box_pack_end(GTK_BOX(windata->actions_box), windata->pie_countdown, FALSE, FALSE, 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); + G_CALLBACK(countdown_expose_cb), windata); } } - if (windata->action_icons) { + if (windata->action_icons) + { button = gtk_button_new_from_icon_name(key, GTK_ICON_SIZE_BUTTON); goto add_button; } @@ -786,7 +799,7 @@ add_notification_action(GtkWindow *nw, const char *text, const char *key, button = gtk_button_new(); gtk_widget_show(button); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); - gtk_widget_set_name(GTK_WIDGET(hbox) , "actions_hbox"); + gtk_widget_set_name(GTK_WIDGET(hbox), "actions_hbox"); gtk_widget_set_valign(GTK_WIDGET(hbox), GTK_ALIGN_END); gtk_container_set_border_width(GTK_CONTAINER(hbox), 0); gtk_widget_show(hbox); @@ -804,26 +817,29 @@ add_notification_action(GtkWindow *nw, const char *text, const char *key, { GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf); gtk_widget_show(image); - gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); - gtk_widget_set_halign (image, GTK_ALIGN_END); - gtk_widget_set_valign (image, GTK_ALIGN_END); + gtk_box_pack_start(GTK_BOX(hbox), image, + FALSE, FALSE, 0); + gtk_widget_set_halign(image, GTK_ALIGN_END); + gtk_widget_set_valign(image, GTK_ALIGN_END); } label = gtk_label_new(NULL); - gtk_widget_set_name(GTK_WIDGET(label) , "actions_label"); + gtk_widget_set_name(GTK_WIDGET(label), "actions_label"); gtk_widget_show(label); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0); - gtk_label_set_xalign (GTK_LABEL (label), 0.0); - gtk_label_set_yalign (GTK_LABEL (label), 1.0); + gtk_box_pack_start(GTK_BOX(hbox), label, + FALSE, TRUE, 0); + gtk_label_set_xalign(GTK_LABEL(label), 0.0); + gtk_label_set_yalign(GTK_LABEL(label), 1.0); gtk_widget_set_valign(GTK_WIDGET(label), GTK_ALIGN_END); - gtk_label_set_text(GTK_LABEL(label) , text); + gtk_label_set_text(GTK_LABEL(label), text); add_button: gtk_widget_set_valign(GTK_WIDGET(button), GTK_ALIGN_END); gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); - - gtk_widget_set_name(GTK_WIDGET(button) , "actions_button"); - gtk_box_pack_start(GTK_BOX(windata->actions_box), button, FALSE, FALSE, 0); + + gtk_widget_set_name(GTK_WIDGET(button), "actions_button"); + gtk_box_pack_start(GTK_BOX(windata->actions_box), button, + FALSE, FALSE, 0); g_object_set_data(G_OBJECT(button), "_nw", nw); g_object_set_data_full(G_OBJECT(button), @@ -835,8 +851,7 @@ add_button: } /* Clear notification actions */ -void -clear_notification_actions(GtkWindow *nw) +void clear_notification_actions(GtkWindow *nw) { WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata"); @@ -848,16 +863,14 @@ clear_notification_actions(GtkWindow *nw) } /* Move notification window */ -void -move_notification(GtkWidget *nw, int x, int y) +void move_notification(GtkWidget *nw, int x, int y) { WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata"); g_assert(windata != NULL); - + gtk_window_move(GTK_WINDOW(nw), x, y); } - /* Optional Functions */ /* Destroy notification */ @@ -867,8 +880,7 @@ move_notification(GtkWidget *nw, int x, int y) /* Hide notification */ /* Set notification timeout */ -void -set_notification_timeout(GtkWindow *nw, glong timeout) +void set_notification_timeout(GtkWindow *nw, glong timeout) { WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata"); g_assert(windata != NULL); @@ -891,9 +903,12 @@ void set_notification_hints(GtkWindow *nw, GVariant *hints) { windata->urgency = g_variant_get_byte(value); - if (windata->urgency == URGENCY_CRITICAL) { + if (windata->urgency == URGENCY_CRITICAL) + { gtk_window_set_title(GTK_WINDOW(nw), "Critical Notification"); - } else { + } + else + { gtk_window_set_title(GTK_WINDOW(nw), "Notification"); } } @@ -906,15 +921,17 @@ void set_notification_hints(GtkWindow *nw, GVariant *hints) } /* Notification tick */ -void -notification_tick(GtkWindow *nw, glong remaining) +void notification_tick(GtkWindow *nw, glong remaining) { WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata"); windata->remaining = remaining; if (windata->pie_countdown != NULL) { - gtk_widget_queue_draw_area(windata->pie_countdown, 0, 0, - PIE_WIDTH, PIE_HEIGHT); + gtk_widget_queue_draw_area(windata->pie_countdown, + 0, + 0, + PIE_WIDTH, + PIE_HEIGHT); } } -- 2.27.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2