From fdb4b281f45e012005f01a6bc430e2a3f9875c17 Mon Sep 17 00:00:00 2001 From: Steve Zesch Date: Thu, 17 Jan 2013 14:21:48 -0500 Subject: Can now select which monitor to display a notification on. mate-notification-properties now offers the user the option to to display notifications on the active monitor (previous default behavior) or to display them on a specific monitor. --- src/capplet/mate-notification-properties.c | 200 ++++++++++++++++++++- src/capplet/mate-notification-properties.ui | 258 ++++++++++++++++++---------- 2 files changed, 360 insertions(+), 98 deletions(-) (limited to 'src/capplet') diff --git a/src/capplet/mate-notification-properties.c b/src/capplet/mate-notification-properties.c index 2c5612e..2c8c71c 100644 --- a/src/capplet/mate-notification-properties.c +++ b/src/capplet/mate-notification-properties.c @@ -23,7 +23,9 @@ #include #include +#include #include +#include #include #include #include @@ -33,6 +35,8 @@ #define GSETTINGS_SCHEMA "org.mate.NotificationDaemon" #define GSETTINGS_KEY_THEME "theme" #define GSETTINGS_KEY_POPUP_LOCATION "popup-location" +#define GSETTINGS_KEY_MONITOR_NUMBER "monitor-number" +#define GSETTINGS_KEY_USE_ACTIVE_MONITOR "use-active-monitor" #define NOTIFICATION_UI_FILE "mate-notification-properties.ui" @@ -41,8 +45,11 @@ typedef struct { GtkWidget* dialog; GtkWidget* position_combo; + GtkWidget* monitor_combo; GtkWidget* theme_combo; GtkWidget* preview_button; + GtkWidget* active_checkbox; + GtkWidget* monitor_label; NotifyNotification* preview; } NotificationAppletDialog; @@ -53,6 +60,11 @@ enum { N_COLUMNS_POSITION }; +enum { + NOTIFY_MONITOR_NUMBER, + N_COLUMNS_MONITOR +}; + enum { NOTIFY_THEME_LABEL, NOTIFY_THEME_NAME, @@ -60,7 +72,7 @@ enum { N_COLUMNS_THEME }; -static void notification_properties_location_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) +static void notification_properties_position_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) { GtkTreeModel* model; GtkTreeIter iter; @@ -89,6 +101,49 @@ static void notification_properties_location_notify(GSettings *settings, gchar * } } +static void notification_properties_monitor_changed(GtkComboBox* widget, NotificationAppletDialog* dialog) +{ + gint monitor; + GtkTreeIter iter; + + GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(dialog->monitor_combo)); + + if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(dialog->monitor_combo), &iter)) + { + return; + } + + gtk_tree_model_get(model, &iter, NOTIFY_MONITOR_NUMBER, &monitor, -1); + + g_settings_set_int(dialog->gsettings, GSETTINGS_KEY_MONITOR_NUMBER, monitor); +} + +static void notification_properties_monitor_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) +{ + GtkTreeModel* model; + GtkTreeIter iter; + gint monitor_number; + gint monitor_number_at_iter; + gboolean valid; + + model = gtk_combo_box_get_model(GTK_COMBO_BOX(dialog->monitor_combo)); + + //g_signal_connect(dialog->monitor_combo, "changed", G_CALLBACK(notification_properties_monitor_changed), dialog); + + monitor_number = g_settings_get_int(dialog->gsettings, GSETTINGS_KEY_MONITOR_NUMBER); + + for (valid = gtk_tree_model_get_iter_first(model, &iter); valid; valid = gtk_tree_model_iter_next(model, &iter)) + { + gtk_tree_model_get(model, &iter, NOTIFY_MONITOR_NUMBER, &monitor_number_at_iter, -1); + + if (monitor_number_at_iter == monitor_number) + { + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dialog->monitor_combo), &iter); + break; + } + } +} + static void notification_properties_location_changed(GtkComboBox* widget, NotificationAppletDialog* dialog) { char* location; @@ -135,10 +190,64 @@ static void notification_properties_dialog_setup_positions(NotificationAppletDia g_free(key); } - g_signal_connect (dialog->gsettings, "changed::" GSETTINGS_KEY_POPUP_LOCATION, G_CALLBACK (notification_properties_location_notify), dialog); + g_signal_connect (dialog->gsettings, "changed::" GSETTINGS_KEY_POPUP_LOCATION, G_CALLBACK (notification_properties_position_notify), dialog); g_free(location); } +static void notification_properties_dialog_setup_monitors(NotificationAppletDialog* dialog) +{ + GtkListStore *store; + GdkDisplay *display; + GdkScreen *screen; + GtkTreeIter iter; + gint num_monitors; + gint cur_monitor_number; + gint cur_monitor_number_at_iter; + gboolean valid; + + // Assumes the user has only one display. + // TODO: add support for multiple displays. + display = gdk_display_get_default(); + g_assert(display != NULL); + + // Assumes the user has only one screen. + // TODO: add support for mulitple screens. + screen = gdk_display_get_default_screen(display); + g_assert(screen != NULL); + + num_monitors = gdk_screen_get_n_monitors(screen); + g_assert(num_monitors >= 1); + + store = gtk_list_store_new(N_COLUMNS_MONITOR, G_TYPE_INT); + + gint i; + for (i = 0; i < num_monitors; i++) + { + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, NOTIFY_MONITOR_NUMBER, i, -1); + } + + gtk_combo_box_set_model(GTK_COMBO_BOX (dialog->monitor_combo), GTK_TREE_MODEL (store)); + + cur_monitor_number = g_settings_get_int(dialog->gsettings, GSETTINGS_KEY_MONITOR_NUMBER); + + for (valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL (store), &iter); valid; valid = gtk_tree_model_iter_next(GTK_TREE_MODEL (store), &iter)) + { + gtk_tree_model_get(GTK_TREE_MODEL (store), &iter, NOTIFY_MONITOR_NUMBER, &cur_monitor_number_at_iter, -1); + + if (cur_monitor_number_at_iter == cur_monitor_number) + { + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dialog->monitor_combo), &iter); + break; + } + } + + g_object_unref(store); + + g_signal_connect(dialog->monitor_combo, "changed", G_CALLBACK(notification_properties_monitor_changed), dialog); + g_signal_connect(dialog->gsettings, "changed::" GSETTINGS_KEY_MONITOR_NUMBER, G_CALLBACK (notification_properties_monitor_notify), dialog); +} + static void notification_properties_theme_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) { const char* theme = g_settings_get_string(dialog->gsettings, key); @@ -272,6 +381,60 @@ static void notification_properties_dialog_setup_themes(NotificationAppletDialog g_free(theme); } +static void notification_properties_checkbox_toggled(GtkWidget* widget, NotificationAppletDialog* dialog) +{ + gboolean is_active; + + is_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget)); + + // This was called as a result of notification_properties_checkbox_notify being called. + // Stop here instead of doing redundant work. + if (is_active == g_settings_get_boolean(dialog->gsettings, GSETTINGS_KEY_USE_ACTIVE_MONITOR)) + { + return; + } + + if (is_active) + { + g_settings_set_boolean(dialog->gsettings, GSETTINGS_KEY_USE_ACTIVE_MONITOR, TRUE); + gtk_widget_set_sensitive(dialog->monitor_combo, FALSE); + gtk_widget_set_sensitive(dialog->monitor_label, FALSE); + } + else + { + g_settings_set_boolean(dialog->gsettings, GSETTINGS_KEY_USE_ACTIVE_MONITOR, FALSE); + gtk_widget_set_sensitive(dialog->monitor_combo, TRUE); + gtk_widget_set_sensitive(dialog->monitor_label, TRUE); + } +} + +static void notification_properties_checkbox_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) +{ + gboolean is_set; + + is_set = g_settings_get_boolean(settings, key); + + // This was called as a result of notification_properties_checkbox_toggled being called. + // Stop here instead of doing redundant work. + if(is_set == gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (dialog->active_checkbox))) + { + return; + } + + if (is_set) + { + gtk_widget_set_sensitive(dialog->monitor_combo, FALSE); + gtk_widget_set_sensitive(dialog->monitor_label, FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->active_checkbox), TRUE); + } + else + { + gtk_widget_set_sensitive(dialog->monitor_combo, TRUE); + gtk_widget_set_sensitive(dialog->monitor_label, TRUE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->active_checkbox), FALSE); + } +} + static void notification_properties_dialog_help(void) { /* Do nothing */ @@ -381,20 +544,47 @@ static gboolean notification_properties_dialog_init(NotificationAppletDialog* di dialog->position_combo = GTK_WIDGET(gtk_builder_get_object(builder, "position_combo")); g_assert(dialog->position_combo != NULL); + dialog->monitor_combo = GTK_WIDGET(gtk_builder_get_object(builder, "monitor_combo")); + g_assert(dialog->monitor_combo != NULL); + dialog->theme_combo = GTK_WIDGET(gtk_builder_get_object(builder, "theme_combo")); g_assert(dialog->theme_combo != NULL); + + dialog->active_checkbox = GTK_WIDGET(gtk_builder_get_object(builder, "use_active_check")); + g_assert(dialog->active_checkbox != NULL); + dialog->monitor_label = GTK_WIDGET(gtk_builder_get_object(builder, "monitor_label")); + g_assert(dialog->monitor_label != NULL); + g_object_unref(builder); + dialog->gsettings = g_settings_new (GSETTINGS_SCHEMA); + g_signal_connect(dialog->dialog, "response", G_CALLBACK(notification_properties_dialog_response), dialog); g_signal_connect(dialog->dialog, "destroy", G_CALLBACK(notification_properties_dialog_destroyed), dialog); - - dialog->gsettings = g_settings_new (GSETTINGS_SCHEMA); + g_signal_connect(dialog->active_checkbox, "toggled", G_CALLBACK(notification_properties_checkbox_toggled), dialog); + g_signal_connect (dialog->gsettings, "changed::" GSETTINGS_KEY_USE_ACTIVE_MONITOR, G_CALLBACK (notification_properties_checkbox_notify), dialog); notification_properties_dialog_setup_themes(dialog); notification_properties_dialog_setup_positions(dialog); + notification_properties_dialog_setup_monitors(dialog); + + if (g_settings_get_boolean(dialog->gsettings, GSETTINGS_KEY_USE_ACTIVE_MONITOR)) + { + gtk_widget_set_sensitive(dialog->monitor_combo, FALSE); + gtk_widget_set_sensitive(dialog->monitor_label, FALSE); + } + else + { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->active_checkbox), FALSE); + gtk_widget_set_sensitive(dialog->monitor_combo, TRUE); + gtk_widget_set_sensitive(dialog->monitor_label, TRUE); + } + - gtk_widget_show(dialog->dialog); + g_fprintf(stderr, "1111111111111\n"); + gtk_widget_show_all(dialog->dialog); + g_fprintf(stderr, "222222222222\n"); dialog->preview = NULL; diff --git a/src/capplet/mate-notification-properties.ui b/src/capplet/mate-notification-properties.ui index 8d56f21..c59c86b 100644 --- a/src/capplet/mate-notification-properties.ui +++ b/src/capplet/mate-notification-properties.ui @@ -1,8 +1,9 @@ - + - + + False GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 5 Notification Settings @@ -10,36 +11,137 @@ center-on-parent mate-notification-properties dialog - False True - vertical + False 2 + + + True + False + end + + + gtk-help + True + False + False + True + False + + + False + False + 0 + + + + + True + True + False + False + + + True + False + 0 + 0 + + + True + False + 2 + + + True + False + mate-notification-properties + 3 + + + False + False + 0 + + + + + True + False + _Preview + True + + + False + False + 1 + + + + + + + + + False + False + 1 + + + + + gtk-close + True + True + True + False + False + True + + + False + False + 2 + + + + + False + True + end + 0 + + True + False 5 - vertical 6 True + False 0 <b>General Options</b> True False + True 0 True + False True + False @@ -51,13 +153,15 @@ True - 2 + False + 4 2 12 6 True + False @@ -73,6 +177,7 @@ True + False position_liststore @@ -91,6 +196,7 @@ True + False 0 P_osition: True @@ -107,6 +213,7 @@ True + False 0 _Theme: True @@ -118,110 +225,75 @@ GTK_FILL - - - 1 - - - - - False - 1 - - - - - False - 1 - - - - - True - end - - - gtk-help - True - False - True - False - - - False - False - 0 - - - - - True - True - False - - - True - 0 - 0 - + True - 2 - - - True - mate-notification-properties - 3 - - - False - False - 0 - - + False + 0 + _Monitor: + True + monitor_combo + + + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + False - - True - _Preview - True - - - False - False - 1 - + + + 0 + + + 1 + 2 + 2 + 3 + + + + + Use Active Monitor + True + True + False + False + True + True + + + 2 + 3 + 4 + + + True + True + 1 + False - False + True 1 - - - gtk-close - True - True - True - False - True - - - False - False - 2 - - False - end - 0 + True + 1 -- cgit v1.2.1