diff options
author | Steve Zesch <[email protected]> | 2013-01-17 14:21:48 -0500 |
---|---|---|
committer | Steve Zesch <[email protected]> | 2013-01-17 14:21:48 -0500 |
commit | fdb4b281f45e012005f01a6bc430e2a3f9875c17 (patch) | |
tree | 91c817c16814a746658e3a62da385ba5f19bf983 | |
parent | ef8c9fcc148c2f71440943efb1b344ce25880735 (diff) | |
download | mate-notification-daemon-fdb4b281f45e012005f01a6bc430e2a3f9875c17.tar.bz2 mate-notification-daemon-fdb4b281f45e012005f01a6bc430e2a3f9875c17.tar.xz |
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.
-rw-r--r-- | src/capplet/mate-notification-properties.c | 200 | ||||
-rw-r--r-- | src/capplet/mate-notification-properties.ui | 258 |
2 files changed, 360 insertions, 98 deletions
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 <glib/gi18n.h> #include <glib.h> +#include <glib/gprintf.h> #include <gtk/gtk.h> +#include <gdk/gdk.h> #include <gio/gio.h> #include <string.h> #include <libmatenotify/notify.h> @@ -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; @@ -54,13 +61,18 @@ enum { }; enum { + NOTIFY_MONITOR_NUMBER, + N_COLUMNS_MONITOR +}; + +enum { NOTIFY_THEME_LABEL, NOTIFY_THEME_NAME, NOTIFY_THEME_FILENAME, 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 @@ -<?xml version="1.0"?> +<?xml version="1.0" encoding="UTF-8"?> <interface> - <!-- interface-requires gtk+ 2.12 --> + <requires lib="gtk+" version="2.18"/> <!-- interface-naming-policy toplevel-contextual --> <object class="GtkDialog" id="dialog"> + <property name="can_focus">False</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="border_width">5</property> <property name="title" translatable="yes">Notification Settings</property> @@ -10,36 +11,137 @@ <property name="window_position">center-on-parent</property> <property name="icon_name">mate-notification-properties</property> <property name="type_hint">dialog</property> - <property name="has_separator">False</property> <child internal-child="vbox"> <object class="GtkVBox" id="dialog-vbox1"> <property name="visible">True</property> - <property name="orientation">vertical</property> + <property name="can_focus">False</property> <property name="spacing">2</property> + <child internal-child="action_area"> + <object class="GtkHButtonBox" id="dialog-action_area1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="button3"> + <property name="label">gtk-help</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_action_appearance">False</property> + <property name="use_stock">True</property> + <property name="focus_on_click">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button4"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_action_appearance">False</property> + <child> + <object class="GtkAlignment" id="alignment2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xscale">0</property> + <property name="yscale">0</property> + <child> + <object class="GtkHBox" id="hbox3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">2</property> + <child> + <object class="GtkImage" id="image2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="icon_name">mate-notification-properties</property> + <property name="icon-size">3</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label12"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">_Preview</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button5"> + <property name="label">gtk-close</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="receives_default">False</property> + <property name="use_action_appearance">False</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> <child> <object class="GtkVBox" id="vbox4"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="border_width">5</property> - <property name="orientation">vertical</property> <property name="spacing">6</property> <child> <object class="GtkLabel" id="label7"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="xalign">0</property> <property name="label" translatable="yes"><b>General Options</b></property> <property name="use_markup">True</property> </object> <packing> <property name="expand">False</property> + <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkHBox" id="hbox1"> <property name="visible">True</property> + <property name="can_focus">False</property> <child> <object class="GtkLabel" id="label10"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="label" translatable="yes"> </property> </object> <packing> @@ -51,13 +153,15 @@ <child> <object class="GtkTable" id="table3"> <property name="visible">True</property> - <property name="n_rows">2</property> + <property name="can_focus">False</property> + <property name="n_rows">4</property> <property name="n_columns">2</property> <property name="column_spacing">12</property> <property name="row_spacing">6</property> <child> <object class="GtkComboBox" id="theme_combo"> <property name="visible">True</property> + <property name="can_focus">False</property> <child> <object class="GtkCellRendererText" id="theme_cellrenderertext"/> <attributes> @@ -73,6 +177,7 @@ <child> <object class="GtkComboBox" id="position_combo"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="model">position_liststore</property> <child> <object class="GtkCellRendererText" id="position_cellrenderertext"/> @@ -91,6 +196,7 @@ <child> <object class="GtkLabel" id="label9"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="xalign">0</property> <property name="label" translatable="yes">P_osition:</property> <property name="use_markup">True</property> @@ -107,6 +213,7 @@ <child> <object class="GtkLabel" id="label8"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="xalign">0</property> <property name="label" translatable="yes">_Theme:</property> <property name="use_markup">True</property> @@ -118,110 +225,75 @@ <property name="y_options">GTK_FILL</property> </packing> </child> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - <child internal-child="action_area"> - <object class="GtkHButtonBox" id="dialog-action_area1"> - <property name="visible">True</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="button3"> - <property name="label">gtk-help</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - <property name="focus_on_click">False</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button4"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <child> - <object class="GtkAlignment" id="alignment2"> - <property name="visible">True</property> - <property name="xscale">0</property> - <property name="yscale">0</property> <child> - <object class="GtkHBox" id="hbox3"> + <object class="GtkLabel" id="monitor_label"> <property name="visible">True</property> - <property name="spacing">2</property> - <child> - <object class="GtkImage" id="image2"> - <property name="visible">True</property> - <property name="icon_name">mate-notification-properties</property> - <property name="icon-size">3</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">_Monitor:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">monitor_combo</property> + </object> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="monitor_combo"> + <property name="visible">True</property> + <property name="can_focus">False</property> <child> - <object class="GtkLabel" id="label12"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Preview</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> + <object class="GtkCellRendererText" id="monitor_cellrenderertext"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> </child> </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + </packing> + </child> + <child> + <object class="GtkCheckButton" id="use_active_check"> + <property name="label" translatable="yes">Use Active Monitor</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_action_appearance">False</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + </packing> </child> </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> </child> </object> <packing> <property name="expand">False</property> - <property name="fill">False</property> + <property name="fill">True</property> <property name="position">1</property> </packing> </child> - <child> - <object class="GtkButton" id="button5"> - <property name="label">gtk-close</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">2</property> - </packing> - </child> </object> <packing> <property name="expand">False</property> - <property name="pack_type">end</property> - <property name="position">0</property> + <property name="fill">True</property> + <property name="position">1</property> </packing> </child> </object> |