From 5641299a2aef3dd0e4e51fbde34c87d2a2fe620c Mon Sep 17 00:00:00 2001 From: Marek Kasik Date: Tue, 20 Jan 2015 15:03:20 +0100 Subject: [PATCH] notifications: Scroll the view not just the list Scrolling the view gives more room for viewing the list and provides a larger scroll area, making the list easier to use. Set height of content of the panel to 400 pixels. Add frame around the list box. https://bugzilla.gnome.org/show_bug.cgi?id=742520 --- panels/notifications/cc-notifications-panel.c | 96 ++++++++-- panels/notifications/notifications.ui | 179 ++++++++++-------- 2 files changed, 184 insertions(+), 91 deletions(-) diff --git a/panels/notifications/cc-notifications-panel.c b/panels/notifications/cc-notifications-panel.c index 4568e7ea8..db2dba0e0 100644 --- a/panels/notifications/cc-notifications-panel.c +++ b/panels/notifications/cc-notifications-panel.c @@ -39,11 +39,15 @@ struct _CcNotificationsPanel { GSettings *master_settings; GtkBuilder *builder; - GtkListBox *list_box; GCancellable *apps_load_cancellable; GHashTable *known_applications; + + GtkAdjustment *focus_adjustment; + + GList *sections; + GList *sections_reverse; }; struct _CcNotificationsPanelClass { @@ -75,6 +79,8 @@ cc_notifications_panel_dispose (GObject *object) g_clear_object (&panel->builder); g_clear_object (&panel->master_settings); g_clear_pointer (&panel->known_applications, g_hash_table_unref); + g_clear_pointer (&panel->sections, g_list_free); + g_clear_pointer (&panel->sections_reverse, g_list_free); g_cancellable_cancel (panel->apps_load_cancellable); @@ -91,6 +97,47 @@ cc_notifications_panel_finalize (GObject *object) G_OBJECT_CLASS (cc_notifications_panel_parent_class)->finalize (object); } +static gboolean +keynav_failed (GtkWidget *widget, + GtkDirectionType direction, + CcNotificationsPanel *panel) +{ + gdouble value, lower, upper, page; + GList *item, *sections; + + /* Find the widget in the list of GtkWidgets */ + if (direction == GTK_DIR_DOWN) + sections = panel->sections; + else + sections = panel->sections_reverse; + + item = g_list_find (sections, widget); + g_assert (item); + if (item->next) + { + gtk_widget_child_focus (GTK_WIDGET (item->next->data), direction); + return TRUE; + } + + value = gtk_adjustment_get_value (panel->focus_adjustment); + lower = gtk_adjustment_get_lower (panel->focus_adjustment); + upper = gtk_adjustment_get_upper (panel->focus_adjustment); + page = gtk_adjustment_get_page_size (panel->focus_adjustment); + + if (direction == GTK_DIR_UP && value > lower) + { + gtk_adjustment_set_value (panel->focus_adjustment, lower); + return TRUE; + } + else if (direction == GTK_DIR_DOWN && value < upper - page) + { + gtk_adjustment_set_value (panel->focus_adjustment, upper - page); + return TRUE; + } + + return FALSE; +} + static void cc_notifications_panel_init (CcNotificationsPanel *panel) { @@ -120,27 +167,47 @@ cc_notifications_panel_init (CcNotificationsPanel *panel) gtk_builder_get_object (panel->builder, "ccnotify-switch-lock-screen"), "active", G_SETTINGS_BIND_DEFAULT); - panel->list_box = GTK_LIST_BOX (gtk_list_box_new ()); w = GTK_WIDGET (gtk_builder_get_object (panel->builder, - "ccnotify-app-scrolledwindow")); + "ccnotify-main-scrolled-window")); + panel->focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (w)); - gtk_container_add (GTK_CONTAINER (w), GTK_WIDGET (panel->list_box)); - gtk_list_box_set_selection_mode (panel->list_box, GTK_SELECTION_NONE); - gtk_list_box_set_sort_func (panel->list_box, (GtkListBoxSortFunc)sort_apps, NULL, NULL); - gtk_list_box_set_header_func (panel->list_box, + w = GTK_WIDGET (gtk_builder_get_object (panel->builder, + "ccnotify-main-grid")); + gtk_container_set_focus_vadjustment (GTK_CONTAINER (w), panel->focus_adjustment); + + w = GTK_WIDGET (gtk_builder_get_object (panel->builder, + "ccnotify-app-listbox")); + g_signal_connect (w, "keynav-failed", G_CALLBACK (keynav_failed), panel); + + gtk_list_box_set_sort_func (GTK_LIST_BOX (w), (GtkListBoxSortFunc)sort_apps, NULL, NULL); + gtk_list_box_set_header_func (GTK_LIST_BOX (w), cc_list_box_update_header_func, NULL, NULL); - g_signal_connect (panel->list_box, "row-activated", + g_signal_connect (GTK_LIST_BOX (w), "row-activated", G_CALLBACK (select_app), panel); - gtk_widget_set_visible (GTK_WIDGET (panel->list_box), TRUE); - build_app_store (panel); w = GTK_WIDGET (gtk_builder_get_object (panel->builder, - "ccnotify-main-grid")); + "ccnotify-switch-banners")); + panel->sections = g_list_append (panel->sections, w); + panel->sections_reverse = g_list_prepend (panel->sections_reverse, w); + + w = GTK_WIDGET (gtk_builder_get_object (panel->builder, + "ccnotify-switch-lock-screen")); + panel->sections = g_list_append (panel->sections, w); + panel->sections_reverse = g_list_prepend (panel->sections_reverse, w); + + w = GTK_WIDGET (gtk_builder_get_object (panel->builder, + "ccnotify-app-listbox")); + panel->sections = g_list_append (panel->sections, w); + panel->sections_reverse = g_list_prepend (panel->sections_reverse, w); + + w = GTK_WIDGET (gtk_builder_get_object (panel->builder, + "ccnotify-main-scrolled-window")); gtk_container_add (GTK_CONTAINER (panel), w); + gtk_widget_show (w); } @@ -191,7 +258,7 @@ static void add_application (CcNotificationsPanel *panel, Application *app) { - GtkWidget *box, *w, *row; + GtkWidget *box, *w, *row, *list_box; GIcon *icon; int size; @@ -207,7 +274,10 @@ add_application (CcNotificationsPanel *panel, g_object_set_qdata_full (G_OBJECT (row), application_quark (), app, (GDestroyNotify) application_free); - gtk_container_add (GTK_CONTAINER (panel->list_box), row); + list_box = GTK_WIDGET (gtk_builder_get_object (panel->builder, + "ccnotify-app-listbox")); + + gtk_container_add (GTK_CONTAINER (list_box), row); gtk_container_add (GTK_CONTAINER (row), box); w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); diff --git a/panels/notifications/notifications.ui b/panels/notifications/notifications.ui index b54b82c9a..ea692e84e 100644 --- a/panels/notifications/notifications.ui +++ b/panels/notifications/notifications.ui @@ -1,91 +1,114 @@ - - + + + 400 + True + True + never + none + + True False - 134 - 134 - 22 - 22 - vertical - 10 - + True False - True - 0 - Show Pop Up Banners - ccnotify-switch-banners - - - 0 - 0 - 1 - 1 - - - - - True - False - True - 0 - Show in Lock Screen - ccnotify-switch-lock-screen - - - 0 - 1 - 1 - 1 - - - - - True - True - - - 1 - 0 - 1 - 1 - - - - - True - True - - - 1 - 1 - 1 - 1 - - - - - 250 - True - True - 12 - True - True - never - in + 134 + 134 + 22 + 22 + vertical + 10 - + + True + False + True + 0 + Show Pop Up Banners + ccnotify-switch-banners + + + 0 + 0 + 1 + 1 + + + + + True + False + True + 0 + Show in Lock Screen + ccnotify-switch-lock-screen + + + 0 + 1 + 1 + 1 + + + + + True + True + + + 1 + 0 + 1 + 1 + + + + + True + True + + + 1 + 1 + 1 + 1 + + + + + True + False + 12 + True + True + 0 + in + + + True + False + True + True + none + + + + + + + + 0 + 2 + 2 + 1 + - - 0 - 2 - 2 - 1 - + +