Changeset 2512

Show
Ignore:
Timestamp:
01/29/06 13:07:46
Author:
chipx86
Message:

- Patch by Michael Vogt and modified a bit by me to add a close button to notifications. This is similar to the one used in Ubuntu Dapper, with a small placement change and functionality change: the notification no longer emits the ActionInvoked? for the default action when closed. This closes ticket #8.
- Moved data freeing for the standard theme and for theme engine unreffing out of the close functions and into a callback specified through g_object_set_data_full().
- The daemon now listens for when notification windows are destroyed, and reacts appropriately, instead of crashing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/notification-daemon/ChangeLog

    r2511 r2512  
     1Sun Jan 29 13:03:09 PST 2006  Christian Hammond <chipx86@chipx86.com> 
     2 
     3    * src/daemon.c: 
     4    * src/engines.c: 
     5    * themes/standard/theme.c: 
     6      - Patch by Michael Vogt and modified a bit by me to add a close 
     7        button to notifications. This is similar to the one used in Ubuntu 
     8        Dapper, with a small placement change and functionality change: the 
     9        notification no longer emits the ActionInvoked for the default action 
     10        when closed. This closes ticket #8. 
     11      - Moved data freeing for the standard theme and for theme engine 
     12        unreffing out of the close functions and into a callback specified 
     13        through g_object_set_data_full(). 
     14      - The daemon now listens for when notification windows are destroyed, 
     15        and reacts appropriately, instead of crashing. 
     16 
    117Sun Jan 29 12:12:43 PST 2006  Christian Hammond <chipx86@chipx86.com> 
    218 
  • trunk/notification-daemon/src/daemon.c

    r2497 r2512  
    231231 
    232232static void 
    233 _close_notification(NotifyDaemon *daemon, guint id
     233_close_notification(NotifyDaemon *daemon, guint id, gboolean hide_notification
    234234{ 
    235235    NotifyDaemonPrivate *priv = daemon->priv; 
     
    242242        _emit_closed_signal(G_OBJECT(nt->nw)); 
    243243 
    244         theme_hide_notification(nt->nw); 
     244        if (hide_notification) 
     245            theme_hide_notification(nt->nw); 
     246 
    245247        g_hash_table_remove(priv->notification_hash, &id); 
    246248    } 
     249} 
     250 
     251static void 
     252_notification_destroyed_cb(GtkWindow *nw, NotifyDaemon *daemon) 
     253{ 
     254    _close_notification( 
     255        daemon, 
     256        GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(nw), "_notify_id")), 
     257        FALSE); 
    247258} 
    248259 
     
    526537    _action_invoked_cb(nw, "default"); 
    527538 
    528     _close_notification(daemon, 
    529         GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(nw), "_notify_id"))); 
     539    _close_notification( 
     540        daemon, 
     541        GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(nw), "_notify_id")), 
     542        TRUE); 
    530543} 
    531544 
     
    819832        g_object_set_data(G_OBJECT(nw), "_notify_daemon", daemon); 
    820833        new_notification = TRUE; 
     834 
     835        g_signal_connect(G_OBJECT(nw), "button-release-event", 
     836                         G_CALLBACK(window_clicked_cb), daemon); 
     837        g_signal_connect(G_OBJECT(nw), "destroy", 
     838                         G_CALLBACK(_notification_destroyed_cb), daemon); 
    821839    } 
    822840 
     
    930948    } 
    931949 
    932     g_signal_connect(G_OBJECT(nw), "button-release-event", 
    933                      G_CALLBACK(window_clicked_cb), daemon); 
    934  
    935  
    936950    if (!screensaver_active(GTK_WIDGET(nw)) && 
    937951        !fullscreen_window_exists(GTK_WIDGET(nw))) 
     
    966980                                         guint id, GError ** error) 
    967981{ 
    968     _close_notification(daemon, id); 
     982    _close_notification(daemon, id, TRUE); 
    969983 
    970984    return TRUE; 
  • trunk/notification-daemon/src/engines.c

    r2446 r2512  
    4040    g_free(filename); 
    4141 
    42     printf("Loading path '%s'\n", path); 
    4342    engine = g_new0(ThemeEngine, 1); 
    4443    engine->ref_count = 1; 
     
    146145} 
    147146 
     147static void 
     148theme_engine_unref(ThemeEngine *engine) 
     149{ 
     150    engine->ref_count--; 
     151 
     152    if (engine->ref_count == 0) 
     153        destroy_engine(engine); 
     154} 
     155 
    148156GtkWindow * 
    149157theme_create_notification(UrlClickedCb url_clicked_cb) 
     
    151159    ThemeEngine *engine = get_theme_engine(); 
    152160    GtkWindow *nw = engine->create_notification(url_clicked_cb); 
    153     g_object_set_data(G_OBJECT(nw), "_theme_engine", engine); 
     161    g_object_set_data_full(G_OBJECT(nw), "_theme_engine", engine, 
     162                           (GDestroyNotify)theme_engine_unref); 
    154163    engine->ref_count++; 
    155164    return nw; 
     
    161170    ThemeEngine *engine = g_object_get_data(G_OBJECT(nw), "_theme_engine"); 
    162171    engine->destroy_notification(nw); 
    163  
    164     engine->ref_count--; 
    165  
    166     if (engine->ref_count == 0) 
    167         destroy_engine(engine); 
    168172} 
    169173 
  • trunk/notification-daemon/themes/standard/theme.c

    r2467 r2512  
    8383} 
    8484 
     85static void 
     86destroy_windata(WindowData *windata) 
     87{ 
     88    if (windata->gc != NULL) 
     89        g_object_unref(G_OBJECT(windata->gc)); 
     90 
     91    if (windata->border_points != NULL) 
     92        g_free(windata->border_points); 
     93 
     94    if (windata->window_region != NULL) 
     95        gdk_region_destroy(windata->window_region); 
     96} 
     97 
    8598GtkWindow * 
    8699create_notification(UrlClickedCb url_clicked) 
     
    89102    GtkWidget *main_vbox; 
    90103    GtkWidget *hbox; 
     104    GtkWidget *hbox2; 
    91105    GtkWidget *vbox; 
     106    GtkWidget *close_button; 
     107    GtkWidget *image; 
    92108    GtkRequisition req; 
    93109    WindowData *windata; 
     
    98114    win = gtk_window_new(GTK_WINDOW_POPUP); 
    99115    gtk_widget_add_events(win, GDK_BUTTON_RELEASE_MASK); 
    100     g_object_set_data(G_OBJECT(win), "windata", windata); 
     116    g_object_set_data_full(G_OBJECT(win), "windata", windata, 
     117                           (GDestroyNotify)destroy_windata); 
    101118    gtk_widget_set_app_paintable(win, TRUE); 
    102119 
     
    144161    gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); 
    145162 
     163    hbox2 = gtk_hbox_new(FALSE, 6); 
     164    gtk_widget_show(hbox2); 
     165    gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0); 
     166 
    146167    windata->summary_label = gtk_label_new(NULL); 
    147168    gtk_widget_show(windata->summary_label); 
    148     gtk_box_pack_start(GTK_BOX(vbox), windata->summary_label, FALSE, FALSE, 0); 
     169    gtk_box_pack_start(GTK_BOX(hbox2), windata->summary_label, TRUE, TRUE, 0); 
    149170    gtk_misc_set_alignment(GTK_MISC(windata->summary_label), 0, 0); 
    150171    gtk_label_set_line_wrap(GTK_LABEL(windata->summary_label), TRUE); 
     172 
     173    /* Add the close button */ 
     174    close_button = gtk_button_new(); 
     175    gtk_widget_show(close_button); 
     176    gtk_box_pack_start(GTK_BOX(hbox2), close_button, FALSE, FALSE, 0); 
     177    gtk_button_set_relief(GTK_BUTTON(close_button), GTK_RELIEF_NONE); 
     178    gtk_container_set_border_width(GTK_CONTAINER(close_button), 0); 
     179    gtk_widget_set_size_request(close_button, 20, 20); 
     180    g_signal_connect_swapped(G_OBJECT(close_button), "clicked", 
     181                             G_CALLBACK(gtk_widget_destroy), win); 
     182 
     183    image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); 
     184    gtk_widget_show(image); 
     185    gtk_container_add(GTK_CONTAINER(close_button), image); 
    151186 
    152187    windata->body_label = sexy_url_label_new(); 
     
    171206destroy_notification(GtkWindow *nw) 
    172207{ 
    173     WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata"); 
    174     g_assert(windata != NULL); 
    175  
    176     if (windata->gc != NULL) 
    177         g_object_unref(G_OBJECT(windata->gc)); 
    178  
    179     if (windata->border_points != NULL) 
    180         g_free(windata->border_points); 
    181  
    182     if (windata->window_region != NULL) 
    183         gdk_region_destroy(windata->window_region); 
    184  
    185208    gtk_widget_destroy(GTK_WIDGET(nw)); 
    186209}