From 4fabbd18cf4a2b28a5384446de77441ffb0c6b27 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 29 Jun 2016 15:33:30 -0400 Subject: [PATCH] Split future symbols into a new file and added one we need to fix our button cell renderer on 3.20. --- unix/CMakeLists.txt | 1 + unix/drawtext.c | 26 ++------------------------ unix/future.c | 42 ++++++++++++++++++++++++++++++++++++++++++ unix/main.c | 1 + unix/uipriv_unix.h | 5 +++++ 5 files changed, 51 insertions(+), 24 deletions(-) create mode 100644 unix/future.c diff --git a/unix/CMakeLists.txt b/unix/CMakeLists.txt index 10d3d833..2147df24 100644 --- a/unix/CMakeLists.txt +++ b/unix/CMakeLists.txt @@ -24,6 +24,7 @@ list(APPEND _LIBUI_SOURCES unix/entry.c unix/fontbutton.c unix/form.c + unix/future.c unix/graphemes.c unix/grid.c unix/group.c diff --git a/unix/drawtext.c b/unix/drawtext.c index d12fcee9..d31c264c 100644 --- a/unix/drawtext.c +++ b/unix/drawtext.c @@ -273,25 +273,6 @@ static void addAttr(uiDrawTextLayout *layout, PangoAttribute *attr, int startCha // pango_attr_list_insert() takes attr; we don't free it } -// these attributes are only supported on 1.38 and higher; we need to support 1.36 -// use dynamic linking to make them work at least on newer systems -static PangoAttribute *(*newFGAlphaAttr)(guint16 alpha) = NULL; -static gboolean tried138 = FALSE; - -// note that we treat any error as "the 1.38 symbols aren't there" (and don't care if dlclose() failed) -static void try138(void) -{ - void *handle; - - tried138 = TRUE; - // dlsym() walks the dependency chain, so opening the current process should be sufficient - handle = dlopen(NULL, RTLD_LAZY); - if (handle == NULL) - return; - *((void **) (&newFGAlphaAttr)) = dlsym(handle, "pango_attr_foreground_alpha_new"); - dlclose(handle); -} - void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, int startChar, int endChar, double r, double g, double b, double a) { PangoAttribute *attr; @@ -305,11 +286,8 @@ void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, int startChar, int endCh attr = pango_attr_foreground_new(rr, gg, bb); addAttr(layout, attr, startChar, endChar); - if (!tried138) - try138(); // TODO what if aa == 0? - if (newFGAlphaAttr != NULL) { - attr = (*newFGAlphaAttr)(aa); + attr = FUTURE_pango_attr_foreground_alpha_new(aa); + if (attr != NULL) addAttr(layout, attr, startChar, endChar); - } } diff --git a/unix/future.c b/unix/future.c new file mode 100644 index 00000000..1f9f532b --- /dev/null +++ b/unix/future.c @@ -0,0 +1,42 @@ +// 29 june 2016 +#include "uipriv_unix.h" + +// functions FROM THE FUTURE! +// in some cases, because being held back by LTS releases sucks :/ +// in others, because parts of GTK+ being unstable until recently also sucks :/ + +// added in pango 1.38; we need 1.36 +static PangoAttribute *(*newFGAlphaAttr)(guint16 alpha) = NULL; + +// added in GTK+ 3.20; we need 3.10 +static void (*gwpIterSetObjectName)(GtkWidgetPath *path, gint pos, const char *name) = NULL; + +// note that we treat any error as "the symbols aren't there" (and don't care if dlclose() failed) +void loadFutures(void) +{ + void *handle; + + // dlsym() walks the dependency chain, so opening the current process should be sufficient + handle = dlopen(NULL, RTLD_LAZY); + if (handle == NULL) + return; +#define GET(var, fn) *((void **) (&var)) = dlsym(handle, #fn) + GET(newFGAlphaAttr, pango_attr_foreground_alpha_new); + GET(gwpIterSetObjectName, gtk_widget_path_iter_set_object_name); + dlclose(handle); +} + +PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha) +{ + if (newFGAlphaAttr == NULL) + return NULL; + return (*newFGAlphaAttr)(alpha); +} + +gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name) +{ + if (gwpIterSetObjectName == NULL) + return FALSE; + (*gwpIterSetObjectName)(path, pos, name); + return TRUE; +} diff --git a/unix/main.c b/unix/main.c index 13f0a913..9b78c24d 100644 --- a/unix/main.c +++ b/unix/main.c @@ -15,6 +15,7 @@ const char *uiInit(uiInitOptions *o) return msg; } initAlloc(); + loadFutures(); return NULL; } diff --git a/unix/uipriv_unix.h b/unix/uipriv_unix.h index c246f371..d52a83c2 100644 --- a/unix/uipriv_unix.h +++ b/unix/uipriv_unix.h @@ -57,3 +57,8 @@ extern cairo_surface_t *imageAppropriateSurface(uiImage *i, GtkWidget *w); // cellrendererbutton.c extern GtkCellRenderer *newCellRendererButton(void); + +// future.c +extern void loadFutures(void); +extern PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha); +extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name);