Skip to content

Commit

Permalink
gtkui: linux and gtk2 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Nov 17, 2023
1 parent 78fe3b0 commit aa806dc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions plugins/gtkui/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ GTKUI_SOURCES = \
tfimport.c tfimport.h\
medialib/medialibwidget.c medialib/medialibwidget.h\
medialib/medialibmanager.c medialib/medialibmanager.h\
medialib/mlcellrendererpixbuf.c medialib/mlcellrendererpixbuf.h\
covermanager/covermanager.c covermanager/covermanager.h\
covermanager/gobjcache.c covermanager/gobjcache.h\
covermanager/albumartwidget.c covermanager/albumartwidget.h\
Expand Down
35 changes: 27 additions & 8 deletions plugins/gtkui/medialib/mlcellrendererpixbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/

#include <deadbeef/deadbeef.h>
#include <stdlib.h>
#include <string.h>
#include "mlcellrendererpixbuf.h"

extern DB_functions_t *deadbeef;
Expand Down Expand Up @@ -111,8 +113,13 @@ _set_property (
}
}

#if !GTK_CHECK_VERSION(3, 0, 0)
static void
_get_size (GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height) {
#else
static void
_get_size (GtkCellRenderer *cell, GtkWidget *widget, const GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height) {
#endif
if (width != NULL) {
*width = 16;
}
Expand All @@ -121,6 +128,10 @@ _get_size (GtkCellRenderer *cell, GtkWidget *widget, const GdkRectangle *cell_ar
}
}

#if !GTK_CHECK_VERSION(3, 0, 0)
static void
_render (GtkCellRenderer *cell, GdkDrawable *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags) {
#else
static void
_render (
GtkCellRenderer *cell,
Expand All @@ -129,6 +140,7 @@ _render (
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags) {
#endif
MlCellRendererPixbuf *self = ML_CELL_RENDERER_PIXBUF (cell);

GdkRectangle pix_rect;
Expand All @@ -142,23 +154,30 @@ _render (
return;
}

GtkStyleContext *context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);

gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);

GdkPixbuf *pixbuf = self->pixbuf;
if (pixbuf == NULL) {
pixbuf = self->delegate->cell_did_became_visible (self->delegate->ctx, self->path);
}

if (pixbuf) {
if (pixbuf != NULL) {
#if GTK_CHECK_VERSION(3, 0, 0)
GtkStyleContext *context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);

gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
#else
cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
#endif

cairo_rectangle (cr, cell_area->x, cell_area->y, 64, 64);
gdk_cairo_set_source_pixbuf (cr, pixbuf, cell_area->x, cell_area->y);
cairo_fill (cr);
#if GTK_CHECK_VERSION(3, 0, 0)
gtk_style_context_restore (context);
#else
cairo_destroy (cr);
#endif
}

gtk_style_context_restore (context);
}

static void
Expand Down
17 changes: 16 additions & 1 deletion plugins/gtkui/medialib/mlcellrendererpixbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,22 @@ typedef struct {
} MlCellRendererPixbufDelegate;

#define ML_TYPE_CELL_RENDERER_PIXBUF (ml_cell_renderer_pixbuf_get_type ())
G_DECLARE_FINAL_TYPE (MlCellRendererPixbuf, ml_cell_renderer_pixbuf, ML, CELL_RENDERER_PIXBUF, GtkCellRenderer)

#define ML_DECLARE_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \
GType module_obj_name##_get_type (void); \
typedef struct _##ModuleObjName ModuleObjName; \
typedef struct { \
ParentName##Class parent_class; \
} ModuleObjName##Class; \
\
G_GNUC_UNUSED static inline ModuleObjName *MODULE##_##OBJ_NAME (gpointer ptr) { \
return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); \
} \
G_GNUC_UNUSED static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \
return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); \
}

ML_DECLARE_TYPE (MlCellRendererPixbuf, ml_cell_renderer_pixbuf, ML, CELL_RENDERER_PIXBUF, GtkCellRenderer)

MlCellRendererPixbuf *
ml_cell_renderer_pixbuf_new (MlCellRendererPixbufDelegate *delegate);
Expand Down

0 comments on commit aa806dc

Please sign in to comment.