Merge branch 'gtk-3-20-fixes'

This commit is contained in:
Colomban Wendling 2016-05-03 00:32:51 +02:00
commit a291a4239a
11 changed files with 145 additions and 45 deletions

View File

@ -113,7 +113,10 @@ nobase_dist_pkgdata_DATA = \
geany.glade
if GTK3
nobase_dist_pkgdata_DATA += geany.css
nobase_dist_pkgdata_DATA += \
geany-3.0.css \
geany-3.20.css \
geany.css
else
nobase_dist_pkgdata_DATA += geany.gtkrc
endif

10
data/geany-3.0.css Normal file
View File

@ -0,0 +1,10 @@
@import "geany.css";
/* make close button on the editor's tabs smaller */
#geany-close-tab-button {
-GtkWidget-focus-padding: 0;
-GtkWidget-focus-line-width: 0;
-GtkButton-default-border: 0;
-GtkButton-default-outside-border: 0;
-GtkButton-inner-border: 0;
}

11
data/geany-3.20.css Normal file
View File

@ -0,0 +1,11 @@
@import "geany.css";
/* make close button on the editor's tabs smaller */
#geany-close-tab-button {
outline-offset: 0;
outline-width: 0;
margin: 0;
margin-left: 0.5em;
min-width: 0;
min-height: 0;
}

View File

@ -2,19 +2,16 @@
/* make close button on the editor's tabs smaller */
#geany-close-tab-button {
-GtkWidget-focus-padding: 0;
-GtkWidget-focus-line-width: 0;
-GtkButton-default-border: 0;
-GtkButton-default-outside-border: 0;
-GtkButton-inner-border: 0;
padding: 0;
}
#geany-close-tab-button GtkImage {
#geany-close-tab-button GtkImage /* GTK < 3.20 */,
#geany-close-tab-button image /* GTK >= 3.20 */ {
padding: 0;
}
/* use monospaced font in search entries for easier reading of regexp (#1907117) */
#GeanyDialogSearch GtkEntry {
#GeanyDialogSearch GtkEntry /* GTK < 3.20 */,
#GeanyDialogSearch entry /* GTK >= 3.20 */ {
font-family: monospace;
}

View File

@ -138,6 +138,7 @@ Section "!Program Files" SEC01
File "${RESOURCEDIR}\data\filetype_extensions.conf"
File "${RESOURCEDIR}\data\geany.glade"
!if ${GTK_VERSION} >= 3
File "${RESOURCEDIR}\data\geany-3.20.css"
File "${RESOURCEDIR}\data\geany.css"
!else
File "${RESOURCEDIR}\data\geany.gtkrc"

View File

@ -1263,6 +1263,30 @@ ListBox *ListBox::Allocate() {
return lb;
}
static int treeViewGetRowHeight(GtkTreeView *view) {
#if GTK_CHECK_VERSION(3,0,0)
// This version sometimes reports erroneous results on GTK2, but the GTK2
// version is inaccurate for GTK 3.14.
GdkRectangle rect;
GtkTreePath *path = gtk_tree_path_new_first();
gtk_tree_view_get_background_area(view, path, NULL, &rect);
gtk_tree_path_free(path);
return rect.height;
#else
int row_height=0;
int vertical_separator=0;
int expander_size=0;
GtkTreeViewColumn *column = gtk_tree_view_get_column(view, 0);
gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &row_height);
gtk_widget_style_get(GTK_WIDGET(view),
"vertical-separator", &vertical_separator,
"expander-size", &expander_size, NULL);
row_height += vertical_separator;
row_height = Platform::Maximum(row_height, expander_size);
return row_height;
#endif
}
// SmallScroller, a GtkScrolledWindow that can shrink very small, as
// gtk_widget_set_size_request() cannot shrink widgets on GTK3
typedef struct {
@ -1287,9 +1311,19 @@ G_DEFINE_TYPE(SmallScroller, small_scroller, GTK_TYPE_SCROLLED_WINDOW)
#if GTK_CHECK_VERSION(3,0,0)
static void small_scroller_get_preferred_height(GtkWidget *widget, gint *min, gint *nat) {
GTK_WIDGET_CLASS(small_scroller_parent_class)->get_preferred_height(widget, min, nat);
if (*min > 1)
*min = 1;
GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget));
if (GTK_IS_TREE_VIEW(child)) {
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(child));
int n_rows = gtk_tree_model_iter_n_children(model, NULL);
int row_height = treeViewGetRowHeight(GTK_TREE_VIEW(child));
*min = MAX(1, row_height);
*nat = MAX(*min, n_rows * row_height);
} else {
GTK_WIDGET_CLASS(small_scroller_parent_class)->get_preferred_height(widget, min, nat);
if (*min > 1)
*min = 1;
}
}
#else
static void small_scroller_size_request(GtkWidget *widget, GtkRequisition *req) {
@ -1456,7 +1490,7 @@ void ListBoxX::SetFont(Font &scint_font) {
if (cssProvider) {
PangoFontDescription *pfd = PFont(scint_font)->pfd;
std::ostringstream ssFontSetting;
ssFontSetting << "GtkTreeView { ";
ssFontSetting << "GtkTreeView, treeview { ";
ssFontSetting << "font-family: " << pango_font_description_get_family(pfd) << "; ";
ssFontSetting << "font-size:";
ssFontSetting << static_cast<double>(pango_font_description_get_size(pfd)) / PANGO_SCALE;
@ -1486,28 +1520,8 @@ int ListBoxX::GetVisibleRows() const {
return desiredVisibleRows;
}
int ListBoxX::GetRowHeight()
{
#if GTK_CHECK_VERSION(3,0,0)
// This version sometimes reports erroneous results on GTK2, but the GTK2
// version is inaccurate for GTK 3.14.
GdkRectangle rect;
GtkTreePath *path = gtk_tree_path_new_first();
gtk_tree_view_get_background_area(GTK_TREE_VIEW(list), path, NULL, &rect);
return rect.height;
#else
int row_height=0;
int vertical_separator=0;
int expander_size=0;
GtkTreeViewColumn *column = gtk_tree_view_get_column(GTK_TREE_VIEW(list), 0);
gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &row_height);
gtk_widget_style_get(PWidget(list),
"vertical-separator", &vertical_separator,
"expander-size", &expander_size, NULL);
row_height += vertical_separator;
row_height = Platform::Maximum(row_height, expander_size);
return row_height;
#endif
int ListBoxX::GetRowHeight() {
return treeViewGetRowHeight(GTK_TREE_VIEW(list));
}
PRectangle ListBoxX::GetDesiredRect() {
@ -1534,12 +1548,35 @@ PRectangle ListBoxX::GetDesiredRect() {
int row_height = GetRowHeight();
#if GTK_CHECK_VERSION(3,0,0)
GtkStyleContext *styleContextFrame = gtk_widget_get_style_context(PWidget(frame));
GtkBorder padding, border;
gtk_style_context_get_padding(styleContextFrame, GTK_STATE_FLAG_NORMAL, &padding);
gtk_style_context_get_border(styleContextFrame, GTK_STATE_FLAG_NORMAL, &border);
GtkStateFlags stateFlagsFrame = gtk_style_context_get_state(styleContextFrame);
GtkBorder padding, border, border_border = { 0, 0, 0, 0 };
gtk_style_context_get_padding(styleContextFrame, stateFlagsFrame, &padding);
gtk_style_context_get_border(styleContextFrame, stateFlagsFrame, &border);
# if GTK_CHECK_VERSION(3,20,0)
// on GTK 3.20 the frame border is in a sub-node "border".
// Unfortunately we need to be built against 3.20 to be able to support this, as it requires
// new API.
GtkStyleContext *styleContextFrameBorder = gtk_style_context_new();
GtkWidgetPath *widget_path = gtk_widget_path_copy(gtk_style_context_get_path(styleContextFrame));
gtk_widget_path_append_type(widget_path, GTK_TYPE_BORDER); // dummy type
gtk_widget_path_iter_set_object_name(widget_path, -1, "border");
gtk_style_context_set_path(styleContextFrameBorder, widget_path);
gtk_widget_path_free(widget_path);
gtk_style_context_get_border(styleContextFrameBorder, stateFlagsFrame, &border_border);
g_object_unref(styleContextFrameBorder);
# else // < 3.20
if (gtk_check_version(3, 20, 0) == NULL) {
// default to 1px all around as it's likely what it is, and so we don't miss 2px height
// on GTK 3.20 when built against an earlier version.
border_border.top = border_border.bottom = border_border.left = border_border.right = 1;
}
# endif
height = (rows * row_height
+ padding.top + padding.bottom
+ border.top + border.bottom
+ border_border.top + border_border.bottom
+ 2 * gtk_container_get_border_width(GTK_CONTAINER(PWidget(list))));
#else
height = (rows * row_height
@ -1560,6 +1597,7 @@ PRectangle ListBoxX::GetDesiredRect() {
#if GTK_CHECK_VERSION(3,0,0)
rc.right += (padding.left + padding.right
+ border.left + border.right
+ border_border.left + border_border.right
+ 2 * gtk_container_get_border_width(GTK_CONTAINER(PWidget(list))));
#else
rc.right += 2 * (PWidget(frame)->style->xthickness

View File

@ -472,8 +472,10 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) {
#else
gdk_window_set_user_data(gtk_widget_get_window(widget), widget);
#endif
#if !GTK_CHECK_VERSION(3,18,0)
gtk_style_context_set_background(gtk_widget_get_style_context(widget),
gtk_widget_get_window(widget));
#endif
gdk_window_show(gtk_widget_get_window(widget));
UnRefCursor(cursor);
#else
@ -1223,7 +1225,9 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) {
gtk_adjustment_set_upper(adjustmentv, nMax + 1);
gtk_adjustment_set_page_size(adjustmentv, nPage);
gtk_adjustment_set_page_increment(adjustmentv, pageScroll);
#if !GTK_CHECK_VERSION(3,18,0)
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmentv));
#endif
modified = true;
}
@ -1242,7 +1246,9 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) {
gtk_adjustment_set_page_size(adjustmenth, pageWidth);
gtk_adjustment_set_page_increment(adjustmenth, pageIncrement);
gtk_adjustment_set_step_increment(adjustmenth, charWidth);
#if !GTK_CHECK_VERSION(3,18,0)
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmenth));
#endif
modified = true;
}
if (modified && (paintState == painting)) {
@ -1769,8 +1775,17 @@ void ScintillaGTK::Resize(int width, int height) {
alloc.x = 0;
alloc.y = 0;
alloc.width = Platform::Maximum(1, width - verticalScrollBarWidth);
alloc.height = Platform::Maximum(1, height - horizontalScrollBarHeight);
alloc.width = 1;
alloc.height = 1;
#if GTK_CHECK_VERSION(3, 0, 0)
// please GTK 3.20 and ask wText what size it wants, although we know it doesn't really need
// anything special as it's ours.
gtk_widget_get_preferred_size(PWidget(wText), &requisition, NULL);
alloc.width = requisition.width;
alloc.height = requisition.height;
#endif
alloc.width = Platform::Maximum(alloc.width, width - verticalScrollBarWidth);
alloc.height = Platform::Maximum(alloc.height, height - horizontalScrollBarHeight);
gtk_widget_size_allocate(GTK_WIDGET(PWidget(wText)), &alloc);
}

View File

@ -1805,7 +1805,13 @@ static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gui
label = gtk_label_new(text);
g_free(text);
#if GTK_CHECK_VERSION(3,0,0)
gtk_style_context_get_color(gtk_widget_get_style_context(label), GTK_STATE_FLAG_INSENSITIVE, &insensitive_color);
{
GtkStyleContext *ctx = gtk_widget_get_style_context(label);
gtk_style_context_save(ctx);
gtk_style_context_get_color(ctx, GTK_STATE_FLAG_INSENSITIVE, &insensitive_color);
gtk_style_context_restore(ctx);
}
#else
insensitive_color = gtk_widget_get_style(label)->text[GTK_STATE_INSENSITIVE];
#endif

View File

@ -3269,7 +3269,7 @@ const GdkColor *document_get_status_color(GeanyDocument *doc)
gtk_widget_path_iter_set_name(path, -1, document_status_styles[status].name);
gtk_style_context_set_screen(ctx, gtk_widget_get_screen(GTK_WIDGET(doc->editor->sci)));
gtk_style_context_set_path(ctx, path);
gtk_style_context_get_color(ctx, GTK_STATE_FLAG_NORMAL, &color);
gtk_style_context_get_color(ctx, gtk_style_context_get_state(ctx), &color);
document_status_styles[status].color.red = 0xffff * color.red;
document_status_styles[status].color.green = 0xffff * color.green;
document_status_styles[status].color.blue = 0xffff * color.blue;

View File

@ -99,10 +99,11 @@ static gboolean geany_pong_area_draw(GtkWidget *area, cairo_t *cr, GeanyPong *se
/* we use the window style context because the area one has a transparent
* background and we want something to paint for the overlay */
GtkStyleContext *ctx = gtk_widget_get_style_context(GTK_WIDGET(self));
GtkStateFlags state = gtk_style_context_get_state(ctx);
GdkRGBA fg, bg;
gtk_style_context_get_color(ctx, GTK_STATE_FLAG_ACTIVE, &fg);
gtk_style_context_get_background_color(ctx, GTK_STATE_FLAG_BACKDROP, &bg);
gtk_style_context_get_color(ctx, state, &fg);
gtk_style_context_get_background_color(ctx, state, &bg);
#else
GtkStyle *style = gtk_widget_get_style(area);
GdkColor fg = style->fg[GTK_STATE_NORMAL];
@ -144,7 +145,7 @@ static gboolean geany_pong_area_draw(GtkWidget *area, cairo_t *cr, GeanyPong *se
layout = pango_cairo_create_layout(cr);
#if GTK_CHECK_VERSION(3, 0, 0)
PangoFontDescription *font = NULL;
gtk_style_context_get(ctx, GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_FONT, &font, NULL);
gtk_style_context_get(ctx, state, GTK_STYLE_PROPERTY_FONT, &font, NULL);
if (font)
{
pango_layout_set_font_description(layout, font);

View File

@ -2475,10 +2475,28 @@ void ui_init_builder(void)
static void init_custom_style(void)
{
#if GTK_CHECK_VERSION(3, 0, 0)
gchar *css_file = g_build_filename(app->datadir, "geany.css", NULL);
const struct {
guint version;
const gchar *file;
} css_files[] = {
/*
* Keep these from newest to oldest,
* and make sure 0 remains last
*/
{ 20, "geany-3.20.css" },
{ 0, "geany-3.0.css" },
};
guint gtk_version = gtk_get_minor_version();
gsize i = 0;
gchar *css_file;
GtkCssProvider *css = gtk_css_provider_new();
GError *error = NULL;
/* gtk_version will never be smaller than 0 */
while (css_files[i].version > gtk_version)
++i;
css_file = g_build_filename(app->datadir, css_files[i].file, NULL);
if (! gtk_css_provider_load_from_path(css, css_file, &error))
{
g_warning("Failed to load custom CSS: %s", error->message);