[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 07/13: Configurable text overlay font and colour, fix background colour change segfault
noreply at xfce.org
noreply at xfce.org
Wed Aug 12 18:39:11 CEST 2015
This is an automated email from the git hooks/post-receive script.
omegaphil pushed a commit to branch master
in repository panel-plugins/xfce4-hardware-monitor-plugin.
commit a99dcc72896bfd4b618cd74e6be30f0311395352
Author: OmegaPhil <OmegaPhil at startmail.com>
Date: Thu Aug 6 19:42:02 2015 +0100
Configurable text overlay font and colour, fix background colour change segfault
---
src/applet.cpp | 40 ++++++++++++++-
src/applet.hpp | 25 +++++----
src/curve-view.cpp | 15 +++++-
src/preferences-window.cpp | 120 ++++++++++++++++++++++++++++++++++++++++----
src/preferences-window.hpp | 53 ++++++++-----------
src/ui.glade | 66 +++++++++++++++++++++++-
6 files changed, 262 insertions(+), 57 deletions(-)
diff --git a/src/applet.cpp b/src/applet.cpp
index 24c0c6d..1b3d254 100644
--- a/src/applet.cpp
+++ b/src/applet.cpp
@@ -167,7 +167,9 @@ Applet::Applet(XfcePanelPlugin *plugin)
next_color(0),
viewer_text_overlay_enabled(false),
viewer_text_overlay_format_string("%a %m"),
- viewer_text_overlay_separator(" ")
+ viewer_text_overlay_separator(" "),
+ viewer_text_overlay_font(""),
+ viewer_text_overlay_color(0x00000000)
{
// Search for settings file
XfceRc* settings_ro = NULL;
@@ -202,6 +204,10 @@ Applet::Applet(XfcePanelPlugin *plugin)
viewer_text_overlay_format_string.c_str());
viewer_text_overlay_separator = xfce_rc_read_entry(settings_ro,
"viewer_text_overlay_separator", viewer_text_overlay_separator.c_str());
+ viewer_text_overlay_font = xfce_rc_read_entry(settings_ro,
+ "viewer_text_overlay_font", viewer_text_overlay_font.c_str());
+ viewer_text_overlay_color = xfce_rc_read_int_entry(settings_ro,
+ "viewer_text_overlay_color", viewer_text_overlay_color);
}
// Loading icon
@@ -564,7 +570,7 @@ void Applet::set_viewer_text_overlay_format_string(const Glib::ustring format_st
viewer_text_overlay_format_string = format_string;
}
-const Glib::ustring Applet::get_viewer_text_overlay_separator()
+const Glib::ustring Applet::get_viewer_text_overlay_separator() const
{
return viewer_text_overlay_separator;
}
@@ -574,6 +580,36 @@ void Applet::set_viewer_text_overlay_separator(const Glib::ustring separator)
viewer_text_overlay_separator = separator;
}
+bool Applet::get_viewer_text_overlay_use_font() const
+{
+ return viewer_text_overlay_use_font;
+}
+
+void Applet::set_viewer_text_overlay_use_font(bool enabled)
+{
+ viewer_text_overlay_use_font = enabled;
+}
+
+const Glib::ustring Applet::get_viewer_text_overlay_font()
+{
+ return viewer_text_overlay_font;
+}
+
+void Applet::set_viewer_text_overlay_font(const Glib::ustring font_details)
+{
+ viewer_text_overlay_font = font_details;
+}
+
+const int Applet::get_viewer_text_overlay_color() const
+{
+ return viewer_text_overlay_color;
+}
+
+void Applet::set_viewer_text_overlay_color(const int color)
+{
+ viewer_text_overlay_color = color;
+}
+
void Applet::add_monitor(Monitor *monitor)
{
add_sync_for(monitor);
diff --git a/src/applet.hpp b/src/applet.hpp
index 77a2da9..cc1e247 100644
--- a/src/applet.hpp
+++ b/src/applet.hpp
@@ -73,8 +73,14 @@ public:
void set_viewer_text_overlay_enabled(bool enabled);
const Glib::ustring get_viewer_text_overlay_format_string();
void set_viewer_text_overlay_format_string(const Glib::ustring format_string);
- const Glib::ustring get_viewer_text_overlay_separator();
+ const Glib::ustring get_viewer_text_overlay_separator() const;
void set_viewer_text_overlay_separator(const Glib::ustring separator);
+ bool get_viewer_text_overlay_use_font() const;
+ void set_viewer_text_overlay_use_font(bool enabled);
+ const Glib::ustring get_viewer_text_overlay_font();
+ void set_viewer_text_overlay_font(const Glib::ustring font_details);
+ const int get_viewer_text_overlay_color() const;
+ void set_viewer_text_overlay_color(const int color);
void viewer_type_listener(const Glib::ustring viewer_type);
void background_color_listener(unsigned int background_color);
void use_background_color_listener(gboolean use_background_color);
@@ -108,17 +114,14 @@ private:
Glib::ustring find_empty_monitor_dir();
// data
- Glib::ustring icon_path;
- Glib::ustring viewer_type;
- Glib::ustring viewer_font;
- bool viewer_text_overlay_enabled;
- Glib::ustring viewer_text_overlay_format_string;
- Glib::ustring viewer_text_overlay_separator;
-
- int viewer_size;
- int background_color;
+ Glib::ustring icon_path, viewer_type, viewer_font;
+ bool viewer_text_overlay_enabled, viewer_text_overlay_use_font;
+ Glib::ustring viewer_text_overlay_format_string, viewer_text_overlay_separator,
+ viewer_text_overlay_font;
+ int viewer_text_overlay_color;
+
+ int viewer_size, background_color, next_color;
gboolean use_background_color;
- int next_color;
Glib::RefPtr<Gdk::Pixbuf> icon;
std::auto_ptr<Gtk::AboutDialog> about;
std::auto_ptr<View> view;
diff --git a/src/curve-view.cpp b/src/curve-view.cpp
index 01dff53..16f4cf1 100644
--- a/src/curve-view.cpp
+++ b/src/curve-view.cpp
@@ -359,8 +359,6 @@ void CurveView::do_draw_loop()
text_overlay = new Gnome::Canvas::Text(*canvas->root());
text_overlay->property_anchor() = Gtk::ANCHOR_NW;
text_overlay->property_text() = overlay_text;
- text_overlay->property_font() = "Sans 8";
- text_overlay->property_fill_color() = "black";
// Positioning text at the bottom of the canvas
text_overlay->property_y() = applet->get_height() -
@@ -370,5 +368,18 @@ void CurveView::do_draw_loop()
// It is - updating if it has changed
else if (text_overlay->property_text() != overlay_text)
text_overlay->property_text() = overlay_text;
+
+ /* Setting/fixing changed font and colour - doing it here since the CurveView
+ * updates so frequently that its not worth also setting it directly from the
+ * UI etc */
+ Glib::ustring font_details = applet->get_viewer_text_overlay_font();
+ if (font_details.empty())
+ font_details = "Sans 8";
+ if (text_overlay->property_font() != font_details)
+ text_overlay->property_font() = font_details;
+
+ int color = applet->get_viewer_text_overlay_color();
+ if (text_overlay->property_fill_color_rgba() != color)
+ text_overlay->property_fill_color_rgba() = color;
}
}
diff --git a/src/preferences-window.cpp b/src/preferences-window.cpp
index d26736c..7c95a02 100644
--- a/src/preferences-window.cpp
+++ b/src/preferences-window.cpp
@@ -119,6 +119,21 @@ PreferencesWindow::PreferencesWindow(Applet &applet_, monitor_seq monitors)
.connect(sigc::mem_fun(*this,
&PreferencesWindow::on_text_overlay_separator_focus_out));
+ ui->get_widget("text_overlay_font_checkbutton", text_overlay_font_checkbutton);
+ text_overlay_font_checkbutton->signal_toggled()
+ .connect(sigc::mem_fun(*this,
+ &PreferencesWindow::on_text_overlay_font_checkbutton_toggled));
+
+ ui->get_widget("text_overlay_fontbutton", text_overlay_fontbutton);
+ text_overlay_fontbutton->signal_font_set()
+ .connect(sigc::mem_fun(*this,
+ &PreferencesWindow::on_text_overlay_fontbutton_set));
+
+ ui->get_widget("text_overlay_colorbutton", text_overlay_colorbutton);
+ text_overlay_colorbutton->signal_color_set()
+ .connect(sigc::mem_fun(*this,
+ &PreferencesWindow::on_text_overlay_colorbutton_set));
+
ui->get_widget("background_colorbutton", background_colorbutton);
background_colorbutton->signal_color_set()
@@ -190,13 +205,16 @@ PreferencesWindow::PreferencesWindow(Applet &applet_, monitor_seq monitors)
background_color_listener(applet.get_background_color());
use_background_color_listener(applet.get_use_background_color());
size_listener(applet.get_viewer_size());
- font_listener(applet.get_viewer_font());
+ font_listener(font_checkbutton, fontbutton, applet.get_viewer_font());
if (applet.get_viewer_text_overlay_enabled())
text_overlay_checkbutton->set_active();
text_overlay_format_string_entry->
set_text(applet.get_viewer_text_overlay_format_string());
text_overlay_separator_entry->
set_text(applet.get_viewer_text_overlay_separator());
+ font_listener(text_overlay_font_checkbutton, text_overlay_fontbutton,
+ applet.get_viewer_text_overlay_font());
+ text_overlay_color_listener(applet.get_viewer_text_overlay_color());
for (monitor_iter i = monitors.begin(), end = monitors.end();
i != end; ++i)
@@ -343,18 +361,21 @@ void PreferencesWindow::size_listener(int viewer_size)
applet.set_viewer_size(viewer_size);
}
-void PreferencesWindow::font_listener(const Glib::ustring viewer_font)
+// This works with more than one font button now
+void PreferencesWindow::font_listener(Gtk::CheckButton *checkbutton,
+ Gtk::FontButton *font_button,
+ const Glib::ustring viewer_font)
{
if (viewer_font.empty())
- font_checkbutton->set_active(false);
+ checkbutton->set_active(false);
else {
- if (fontbutton->get_font_name() != viewer_font)
- fontbutton->set_font_name(viewer_font);
+ if (font_button->get_font_name() != viewer_font)
+ font_button->set_font_name(viewer_font);
/* Must toggle this after setting the font name, otherwise
* on_font_checkbutton_toggled triggers and overwrites the saved
* font details with the default ones */
- font_checkbutton->set_active(true);
+ checkbutton->set_active(true);
}
}
@@ -372,6 +393,19 @@ void PreferencesWindow::monitor_color_listener(unsigned int color)
update_colorbutton_if_different(flame_colorbutton, r, g, b, a);
}
+void PreferencesWindow::text_overlay_color_listener(unsigned int color)
+{
+ unsigned char r = color >> 24,
+ g = color >> 16,
+ b = color >> 8,
+ a = color;
+
+ update_colorbutton_if_different(text_overlay_colorbutton, r, g, b, a);
+
+ // Actually updating the text overlay color
+ applet.set_viewer_text_overlay_color(color);
+}
+
// UI callbacks
@@ -442,7 +476,7 @@ void PreferencesWindow::sync_conf_with_colorbutton(Glib::ustring settings_dir,
void PreferencesWindow::on_background_colorbutton_set()
{
// Settings dir here is the default XFCE4 settings group
- sync_conf_with_colorbutton(NULL, "background_color",
+ sync_conf_with_colorbutton("", "background_color",
background_colorbutton);
// Actually apply the color change
@@ -752,8 +786,6 @@ void PreferencesWindow::on_font_checkbutton_toggled()
{
bool active = font_checkbutton->get_active();
- fontbutton->set_sensitive(active);
-
// Obtaining font_details to set
Glib::ustring font_details;
if (active)
@@ -763,7 +795,7 @@ void PreferencesWindow::on_font_checkbutton_toggled()
// Saving
save_font_details(font_details);
- font_listener(font_details);
+ font_listener(font_checkbutton, fontbutton, font_details);
}
void PreferencesWindow::on_fontbutton_set()
@@ -777,6 +809,9 @@ void PreferencesWindow::on_text_overlay_checkbutton_toggled()
bool active = text_overlay_checkbutton->get_active();
text_overlay_format_string_entry->set_sensitive(active);
text_overlay_separator_entry->set_sensitive(active);
+ text_overlay_font_checkbutton->set_sensitive(active);
+ text_overlay_fontbutton->set_sensitive(active);
+ text_overlay_colorbutton->set_sensitive(active);
save_text_overlay_enabled(active);
}
@@ -797,6 +832,40 @@ bool PreferencesWindow::on_text_overlay_separator_focus_out(GdkEventFocus *event
return FALSE;
}
+void PreferencesWindow::on_text_overlay_font_checkbutton_toggled()
+{
+ bool active = text_overlay_font_checkbutton->get_active();
+
+ // Obtaining font_details to set
+ Glib::ustring font_details;
+ if (active)
+ font_details = text_overlay_fontbutton->get_font_name();
+ else
+ font_details = "";
+
+ // Saving
+ save_text_overlay_font_details(font_details);
+ font_listener(text_overlay_font_checkbutton, text_overlay_fontbutton,
+ font_details);
+}
+
+void PreferencesWindow::on_text_overlay_fontbutton_set()
+{
+ // Saving
+ save_text_overlay_font_details(text_overlay_fontbutton->get_font_name());
+}
+
+void PreferencesWindow::on_text_overlay_colorbutton_set()
+{
+ // Settings dir here is the default XFCE4 settings group
+ sync_conf_with_colorbutton("", "viewer_text_overlay_color",
+ text_overlay_colorbutton);
+
+ // Actually apply the color change
+ applet.set_viewer_text_overlay_color(
+ get_colorbutton_int(text_overlay_colorbutton));
+}
+
void PreferencesWindow::on_add_button_clicked()
{
Monitor *monitor = run_choose_monitor_window(Glib::ustring());
@@ -992,6 +1061,37 @@ void PreferencesWindow::save_font_details(Glib::ustring font_details)
}
}
+void PreferencesWindow::save_text_overlay_font_details(Glib::ustring font_details)
+{
+ applet.set_viewer_text_overlay_font(font_details);
+
+ // Search for a writeable settings file, create one if it doesnt exist */
+ gchar* file = xfce_panel_plugin_save_location(applet.panel_applet, true);
+
+ if (file)
+ {
+ // Opening setting file
+ XfceRc* settings_w = xfce_rc_simple_open(file, false);
+ g_free(file);
+
+ // Ensuring default group is in focus
+ xfce_rc_set_group(settings_w, NULL);
+
+ // Updating configuration
+ xfce_rc_write_entry(settings_w, "viewer_text_overlay_font",
+ font_details.c_str());
+
+ // Close settings file
+ xfce_rc_close(settings_w);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save viewer text overlay font in save_text_overlay_font_details!\n");
+ }
+}
+
void PreferencesWindow::save_text_overlay_enabled(bool enabled)
{
applet.set_viewer_text_overlay_enabled(enabled);
diff --git a/src/preferences-window.hpp b/src/preferences-window.hpp
index a5866b2..bf8133e 100644
--- a/src/preferences-window.hpp
+++ b/src/preferences-window.hpp
@@ -59,42 +59,27 @@ private:
Gtk::Window *window;
Gtk::SpinButton *update_interval_spinbutton;
- Gtk::RadioButton *panel_background_radiobutton;
- Gtk::RadioButton *background_color_radiobutton;
+ Gtk::RadioButton *panel_background_radiobutton, *background_color_radiobutton;
Gtk::ColorButton *background_colorbutton;
- Gtk::RadioButton *curve_radiobutton;
- Gtk::RadioButton *bar_radiobutton;
- Gtk::RadioButton *vbar_radiobutton;
- Gtk::RadioButton *column_radiobutton;
- Gtk::RadioButton *text_radiobutton;
- Gtk::RadioButton *flame_radiobutton;
-
- Gtk::Widget *size_outer_vbox;
+ Gtk::RadioButton *curve_radiobutton, *bar_radiobutton, *vbar_radiobutton,
+ *column_radiobutton, *text_radiobutton, *flame_radiobutton;
+ Gtk::Widget *size_outer_vbox, *font_outer_vbox, *text_overlay_outer_vbox;
Gtk::Scale *size_scale;
- Gtk::Widget *font_outer_vbox;
- Gtk::CheckButton *font_checkbutton;
- Gtk::FontButton *fontbutton;
- Gtk::Widget *text_overlay_outer_vbox;
- Gtk::CheckButton *text_overlay_checkbutton;
- Gtk::Entry *text_overlay_format_string_entry;
- Gtk::Entry *text_overlay_separator_entry;
-
- Gtk::Button *remove_button;
- Gtk::Button *change_button;
+ Gtk::CheckButton *font_checkbutton, *text_overlay_checkbutton,
+ *text_overlay_font_checkbutton;
+ Gtk::FontButton *fontbutton, *text_overlay_fontbutton;
+ Gtk::Entry *text_overlay_format_string_entry, *text_overlay_separator_entry;
+ Gtk::ColorButton *text_overlay_colorbutton;
+
+ Gtk::Button *remove_button, *change_button;
Gtk::TreeView *monitor_treeview;
Gtk::Widget *monitor_options;
- Gtk::Widget *monitor_curve_options;
- Gtk::ColorButton *line_colorbutton;
- Gtk::Widget *monitor_bar_options;
- Gtk::ColorButton *bar_colorbutton;
- Gtk::Widget *monitor_vbar_options;
- Gtk::ColorButton *vbar_colorbutton;
- Gtk::Widget *monitor_column_options;
- Gtk::ColorButton *column_colorbutton;
- Gtk::Widget *monitor_flame_options;
- Gtk::ColorButton *flame_colorbutton;
+ Gtk::Widget *monitor_curve_options, *monitor_bar_options, *monitor_vbar_options,
+ *monitor_column_options, *monitor_flame_options;
+ Gtk::ColorButton *line_colorbutton, *bar_colorbutton, *vbar_colorbutton,
+ *column_colorbutton, *flame_colorbutton;
class MonitorColumns: public Gtk::TreeModel::ColumnRecord
{
@@ -113,8 +98,10 @@ private:
void background_color_listener(unsigned int background_color);
void use_background_color_listener(bool use_background_color);
void size_listener(int viewer_size);
- void font_listener(const Glib::ustring viewer_font);
+ void font_listener(Gtk::CheckButton *checkbutton, Gtk::FontButton *font_button,
+ const Glib::ustring viewer_font);
void monitor_color_listener(unsigned int color);
+ void text_overlay_color_listener(unsigned int color);
void stop_monitor_listeners();
@@ -139,6 +126,9 @@ private:
void on_text_overlay_checkbutton_toggled();
bool on_text_overlay_format_string_focus_out(GdkEventFocus *event);
bool on_text_overlay_separator_focus_out(GdkEventFocus *event);
+ void on_text_overlay_font_checkbutton_toggled();
+ void on_text_overlay_fontbutton_set();
+ void on_text_overlay_colorbutton_set();
void on_add_button_clicked();
void on_remove_button_clicked();
@@ -161,6 +151,7 @@ private:
void save_font_details(Glib::ustring font_details);
void save_text_overlay_enabled(bool enabled);
+ void save_text_overlay_font_details(Glib::ustring font_details);
void save_text_overlay_format_string(const Glib::ustring format_string);
void save_text_overlay_separator(const Glib::ustring separator);
diff --git a/src/ui.glade b/src/ui.glade
index 6d1c38a..079cd56 100644
--- a/src/ui.glade
+++ b/src/ui.glade
@@ -2151,7 +2151,6 @@ view</property>
<widget class="GtkCheckButton" id="font_checkbutton">
<property name="label" translatable="yes">Use this f_ont:</property>
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
@@ -2339,6 +2338,71 @@ individual monitor values</property>
<property name="position">4</property>
</packing>
</child>
+ <child>
+ <widget class="GtkHBox" id="text_overlay_font_hbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <widget class="GtkCheckButton" id="text_overlay_font_checkbutton">
+ <property name="label" translatable="yes">Use this font:</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">10</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkFontButton" id="text_overlay_fontbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="title" translatable="yes">Choose a Font</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="text_overlay_color_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Color:</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">12</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkColorButton" id="text_overlay_colorbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="color">#000000000000</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">5</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="expand">True</property>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list