libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xpngloader.h File Reference
#include "xputty.h"
#include "xresources.h"
Include dependency graph for xpngloader.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  binary_stream
 binary_stream - struct definition to read binary data into cairo surface More...
 

Macros

#define XPNGLOADER_H_
 
#define EXTLD(NAME)
 
#define LDVAR(NAME)   _binary_ ## NAME ## _start
 
#define LDLEN(NAME)   ((_binary_ ## NAME ## _end) - (_binary_ ## NAME ## _start))
 

Functions

cairo_surface_t * cairo_image_surface_create_from_stream (const unsigned char *name)
 cairo_image_surface_create_from_stream - read binary data into cairo surface from stream More...
 
void widget_get_png (Widget_t *w, const unsigned char *name)
 widget_get_png - read png into Widget_t xlib surface More...
 
void widget_get_scaled_png (Widget_t *w, const unsigned char *name)
 widget_get_scaled_png - read scaled png into Widget_t xlib surface More...
 
void widget_get_surface_ptr (Widget_t *w, Widget_t *wid)
 widget_get_surface_ptr - set pointer to a 2. Widget_t xlib surface More...
 
cairo_surface_t * surface_get_png (Widget_t *w, cairo_surface_t *sf, const unsigned char *name)
 surface_get_png - read png into Widget_t xlib surface More...
 
void widget_set_icon_from_surface (Widget_t *w, Pixmap *icon_, cairo_surface_t *image)
 widget_set_icon_from_surface - set icon image from cairo surface for Widget_t those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager) More...
 
void widget_set_icon_from_png (Widget_t *w, Pixmap *icon_, const unsigned char *name)
 widget_set_icon_from_png - set icon image from png binary to Widget_t those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager) More...
 

Macro Definition Documentation

◆ EXTLD

#define EXTLD (   NAME)
Value:
extern const unsigned char _binary_ ## NAME ## _start[]; \
extern const unsigned char _binary_ ## NAME ## _end[];

define some MACROS to read png data from binary stream png's been converted to object files with ld -r -b binary name.png -o name.o

Definition at line 68 of file xpngloader.h.

◆ LDLEN

#define LDLEN (   NAME)    ((_binary_ ## NAME ## _end) - (_binary_ ## NAME ## _start))

Definition at line 73 of file xpngloader.h.

◆ LDVAR

#define LDVAR (   NAME)    _binary_ ## NAME ## _start

Definition at line 71 of file xpngloader.h.

◆ XPNGLOADER_H_

#define XPNGLOADER_H_

Definition at line 24 of file xpngloader.h.

Function Documentation

◆ cairo_image_surface_create_from_stream()

cairo_surface_t* cairo_image_surface_create_from_stream ( const unsigned char *  name)

cairo_image_surface_create_from_stream - read binary data into cairo surface from stream

Parameters
*name- pointer to the binary image data LDVAR(name)
Returns
cairo_surface_t - the cairo_image_surface

Definition at line 34 of file xpngloader.c.

34  {
35  binary_stream png_stream;
36  png_stream.data = name;
37  png_stream.position = 0;
38  return cairo_image_surface_create_from_png_stream(&png_stream_reader, (void *)&png_stream);
39 }

References binary_stream::data, png_stream_reader(), and binary_stream::position.

◆ surface_get_png()

cairo_surface_t* surface_get_png ( Widget_t w,
cairo_surface_t *  sf,
const unsigned char *  name 
)

surface_get_png - read png into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the png
*sf- pointer to the cairo_surface_t which should hold the png
*name- pointer to the binary image data LDVAR(name)
Returns
cairo_surface_t - the cairo_xlib_surface, you need to free it by yourself

Definition at line 83 of file xpngloader.c.

83  {
84  cairo_surface_t *getpng = cairo_image_surface_create_from_stream (name);
85  int width = cairo_image_surface_get_width(getpng);
86  int height = cairo_image_surface_get_height(getpng);
87 
88  sf = cairo_surface_create_similar (w->surface,
89  CAIRO_CONTENT_COLOR_ALPHA, width, height);
90  cairo_t *cri = cairo_create (sf);
91  cairo_set_source_surface (cri, getpng,0,0);
92  cairo_paint (cri);
93  cairo_surface_destroy(getpng);
94  cairo_destroy(cri);
95  return sf;
96 }

References cairo_image_surface_create_from_stream(), and Widget_t::surface.

◆ widget_get_png()

void widget_get_png ( Widget_t w,
const unsigned char *  name 
)

widget_get_png - read png into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the png
*name- pointer to the binary image data LDVAR(name)
Returns
void

Definition at line 41 of file xpngloader.c.

41  {
42  cairo_surface_t *getpng = cairo_image_surface_create_from_stream (name);
43  int width = cairo_image_surface_get_width(getpng);
44  int height = cairo_image_surface_get_height(getpng);
45  cairo_surface_destroy(w->image);
46  w->image = NULL;
47 
48  w->image = cairo_surface_create_similar (w->surface,
49  CAIRO_CONTENT_COLOR_ALPHA, width, height);
50  cairo_t *cri = cairo_create (w->image);
51  cairo_set_source_surface (cri, getpng,0,0);
52  cairo_paint (cri);
53  cairo_surface_destroy(getpng);
54  cairo_destroy(cri);
55 }

References cairo_image_surface_create_from_stream(), Widget_t::image, and Widget_t::surface.

◆ widget_get_scaled_png()

void widget_get_scaled_png ( Widget_t w,
const unsigned char *  name 
)

widget_get_scaled_png - read scaled png into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the png
*name- pointer to the binary image data LDVAR(name)
Returns
void

Definition at line 57 of file xpngloader.c.

57  {
58  cairo_surface_t *getpng = cairo_image_surface_create_from_stream (name);
59  int width = cairo_image_surface_get_width(getpng);
60  int height = cairo_image_surface_get_height(getpng);
61  int width_t = w->scale.init_width;
62  int height_t = w->scale.init_height;
63  double x = (double)width_t/(double)width;
64  double y = (double)height_t/(double)height;
65  cairo_surface_destroy(w->image);
66  w->image = NULL;
67 
68  w->image = cairo_surface_create_similar (w->surface,
69  CAIRO_CONTENT_COLOR_ALPHA, width_t, height_t);
70  cairo_t *cri = cairo_create (w->image);
71  cairo_scale(cri, x,y);
72  cairo_set_source_surface (cri, getpng,0,0);
73  cairo_paint (cri);
74  cairo_surface_destroy(getpng);
75  cairo_destroy(cri);
76 }

References cairo_image_surface_create_from_stream(), Widget_t::image, Resize_t::init_height, Resize_t::init_width, Widget_t::scale, and Widget_t::surface.

◆ widget_get_surface_ptr()

void widget_get_surface_ptr ( Widget_t w,
Widget_t wid 
)

widget_get_surface_ptr - set pointer to a 2. Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the surface
*wid- pointer to the Widget_t which hold the surface
Returns
void

Definition at line 78 of file xpngloader.c.

78  {
79  w->image = wid->image;
80  w->flags |= REUSE_IMAGE;
81 }

References Widget_t::flags, Widget_t::image, and REUSE_IMAGE.

◆ widget_set_icon_from_png()

void widget_set_icon_from_png ( Widget_t w,
Pixmap *  icon_,
const unsigned char *  name 
)

widget_set_icon_from_png - set icon image from png binary to Widget_t those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager)

Parameters
*w- pointer to the Widget_t which should use the icon
*name- pointer to the binary image data LDVAR(name)
Returns
void

Definition at line 124 of file xpngloader.c.

124  {
125  cairo_surface_t *image = cairo_image_surface_create_from_stream (name);
126  int width = cairo_image_surface_get_width(image);
127  int height = cairo_image_surface_get_height(image);
128  XWindowAttributes atr;
129  XGetWindowAttributes (w->app->dpy, w->widget, &atr);
130  Pixmap icon = XCreatePixmap(w->app->dpy, w->widget, width, height, atr.depth);
131  cairo_surface_t *surface = cairo_xlib_surface_create (w->app->dpy, icon,
132  DefaultVisual(w->app->dpy, DefaultScreen(w->app->dpy)), width, height);
133  cairo_t *cri = cairo_create (surface);
135  cairo_set_source_rgba(cri, c->bg[0], c->bg[1], c->bg[2], c->bg[3]);
136  cairo_paint(cri);
137  cairo_set_source_surface (cri, image,0,0);
138  cairo_paint(cri);
139  cairo_surface_destroy(image);
140  cairo_surface_destroy(surface);
141  cairo_destroy(cri);
142  icon_ = &icon;
143 
144  XWMHints* win_hints = XAllocWMHints();
145  assert(win_hints);
146  win_hints->flags = IconPixmapHint;
147  win_hints->icon_pixmap = icon;
148  XSetWMHints(w->app->dpy, w->widget, win_hints);
149  XFree(win_hints);
150 }

References Widget_t::app, Colors::bg, cairo_image_surface_create_from_stream(), Xputty::dpy, get_color_scheme(), PRELIGHT_, and Widget_t::widget.

◆ widget_set_icon_from_surface()

void widget_set_icon_from_surface ( Widget_t w,
Pixmap *  icon_,
cairo_surface_t *  image 
)

widget_set_icon_from_surface - set icon image from cairo surface for Widget_t those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager)

Parameters
*w- pointer to the Widget_t which should use the icon
*image- pointer to the cairo_surface_t to use for the icon
Returns
void

Definition at line 98 of file xpngloader.c.

98  {
99  int width = cairo_xlib_surface_get_width(image);
100  int height = cairo_xlib_surface_get_height(image);
101  XWindowAttributes atr;
102  XGetWindowAttributes (w->app->dpy, w->widget, &atr);
103  Pixmap icon = XCreatePixmap(w->app->dpy, w->widget, width, height, atr.depth);
104  cairo_surface_t *surface = cairo_xlib_surface_create (w->app->dpy, icon,
105  DefaultVisual(w->app->dpy, DefaultScreen(w->app->dpy)), width, height);
106  cairo_t *cri = cairo_create (surface);
108  cairo_set_source_rgba(cri, c->bg[0], c->bg[1], c->bg[2], c->bg[3]);
109  cairo_paint(cri);
110  cairo_set_source_surface (cri, image,0,0);
111  cairo_paint(cri);
112  cairo_surface_destroy(surface);
113  cairo_destroy(cri);
114  icon_ = &icon;
115 
116  XWMHints* win_hints = XAllocWMHints();
117  assert(win_hints);
118  win_hints->flags = IconPixmapHint;
119  win_hints->icon_pixmap = icon;
120  XSetWMHints(w->app->dpy, w->widget, win_hints);
121  XFree(win_hints);
122 }

References Widget_t::app, Colors::bg, Xputty::dpy, get_color_scheme(), PRELIGHT_, and Widget_t::widget.

Widget_t::image
cairo_surface_t * image
Definition: xwidget.h:320
Colors::bg
double bg[4]
Definition: xcolor.h:75
REUSE_IMAGE
@ REUSE_IMAGE
Definition: xwidget.h:259
binary_stream
binary_stream - struct definition to read binary data into cairo surface
Definition: xpngloader.h:91
Widget_t::flags
long long flags
Definition: xwidget.h:324
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
Colors
Color_t - struct used to set cairo color for Widget_t.
Definition: xcolor.h:73
Widget_t::widget
Window widget
Definition: xwidget.h:302
cairo_image_surface_create_from_stream
cairo_surface_t * cairo_image_surface_create_from_stream(const unsigned char *name)
cairo_image_surface_create_from_stream - read binary data into cairo surface from stream
Definition: xpngloader.c:34
binary_stream::data
const unsigned char * data
Definition: xpngloader.h:92
PRELIGHT_
@ PRELIGHT_
Definition: xcolor.h:40
Widget_t::surface
cairo_surface_t * surface
Definition: xwidget.h:312
binary_stream::position
long int position
Definition: xpngloader.h:93
get_color_scheme
Colors * get_color_scheme(Xputty *main, Color_state st)
get_color_scheme - get pointer to the Colors struct to use in relation to the Color_state
Definition: xcolor.c:130
png_stream_reader
cairo_status_t png_stream_reader(void *_stream, unsigned char *data, unsigned int length)
Definition: xpngloader.c:27
Resize_t::init_width
int init_width
Definition: xwidget.h:198
Resize_t::init_height
int init_height
Definition: xwidget.h:200