[gparted] Change Gtk::ProgressBar appearance by providing custom CSS (#7)
- From: Mike Fleetwood <mfleetwo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Change Gtk::ProgressBar appearance by providing custom CSS (#7)
- Date: Mon, 11 Feb 2019 09:20:25 +0000 (UTC)
commit 6aba93d8c055ad26a467a2283e5b40928e118583
Author: Luca Bacci <luca bacci982 gmail com>
Date: Tue Jan 22 15:45:58 2019 +0100
Change Gtk::ProgressBar appearance by providing custom CSS (#7)
In Gtk3 the progress bar height is fixed and defined by the CSS theme in
use. Changing the widget allocation size does nothing, it is always
rendered the same way.
In many themes, including Adwaita, the progressbar is very, very thin.
Provide custom CSS to specify a height of 8 pixels.
The CSS source string has to be differentiated for Gtk pre and post
3.20, because Gtk 3.20 introduced some breaking changes in the way CSS
is handled.
References:
[1] Migrating from GTK+ 2.x to GTK+ 3 - Parsing of custom resources
https://developer.gnome.org/gtk3/stable/gtk-migrating-GtkStyleContext-parsing.html
[2] Gtk3 Reference Documentation - Changes in GTK+ 3.20
https://developer.gnome.org/gtk3/stable/ch32s10.html
[3] Gnome/HowDoI - Custom Style
https://wiki.gnome.org/HowDoI/CustomStyle
Closes #7 - Port to Gtk3
include/Win_GParted.h | 1 +
src/Win_GParted.cc | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
---
diff --git a/include/Win_GParted.h b/include/Win_GParted.h
index c2cb5b0c..80341317 100644
--- a/include/Win_GParted.h
+++ b/include/Win_GParted.h
@@ -64,6 +64,7 @@ private:
void create_format_menu_add_item( FSType filesystem, bool activate );
void init_device_info() ;
void init_hpaned_main() ;
+ void add_custom_css();
void refresh_combo_devices() ;
void show_pulsebar( const Glib::ustring & status_message ) ;
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 0d82cc82..08924567 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -48,6 +48,7 @@
#include "../config.h"
#include <string.h>
+#include <gtkmm/cssprovider.h>
#include <gtkmm/aboutdialog.h>
#include <gtkmm/messagedialog.h>
#include <gtkmm/radiobuttongroup.h>
@@ -141,6 +142,8 @@ Win_GParted::Win_GParted( const std::vector<Glib::ustring> & user_devices )
//make sure harddisk information is closed..
hpaned_main .get_child1() ->hide() ;
+
+ add_custom_css();
}
Win_GParted::~Win_GParted()
@@ -669,6 +672,31 @@ void Win_GParted::init_hpaned_main()
hpaned_main .pack2( *scrollwindow, true, true );
}
+void Win_GParted::add_custom_css()
+{
+ Glib::RefPtr<Gdk::Screen> default_screen = Gdk::Screen::get_default();
+ Glib::RefPtr<Gtk::CssProvider> provider = Gtk::CssProvider::create();
+
+ Glib::ustring custom_css;
+ if (gtk_get_minor_version() >= 20)
+ custom_css = "progressbar progress, trough { min-height: 8px; }";
+ else
+ custom_css = "GtkProgressBar { -GtkProgressBar-min-horizontal-bar-height: 8px; }";
+
+ try
+ {
+ provider->load_from_data(custom_css);
+ }
+ catch (Glib::Error& e)
+ {
+ std::cerr << e.what() << std::endl;
+ }
+
+ Gtk::StyleContext::add_provider_for_screen(default_screen,
+ provider,
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
void Win_GParted::refresh_combo_devices()
{
// Temporarily block the on change callback while re-creating the device list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]