Split future symbols into a new file and added one we need to fix our button cell renderer on 3.20.

This commit is contained in:
Pietro Gagliardi 2016-06-29 15:33:30 -04:00
parent 621e301d5f
commit 4fabbd18cf
5 changed files with 51 additions and 24 deletions

View File

@ -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

View File

@ -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);
}
}

42
unix/future.c Normal file
View File

@ -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;
}

View File

@ -15,6 +15,7 @@ const char *uiInit(uiInitOptions *o)
return msg;
}
initAlloc();
loadFutures();
return NULL;
}

View File

@ -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);