File: setfile.c

package info (click to toggle)
chameleon 1.0-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 136 kB
  • ctags: 27
  • sloc: ansic: 356; makefile: 68
file content (63 lines) | stat: -rw-r--r-- 1,177 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
** Routine for putting a picture file on the root window. Uses Imlib.
** ff, 1998.
*/

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Imlib.h>


int set_file(char *name, int stretch)
{
	Display *display;
	ImlibData *id;
	Window window;
	ImlibImage *im;
	Pixmap p, m;
	int w, h, rw, rh, screen;

	display = XOpenDisplay(NULL);

	id = Imlib_init(display);

	if((im = Imlib_load_image(id, name))==NULL)
		return 1;

	window = DefaultRootWindow(display);
	screen = DefaultScreen(display);

	rw = DisplayWidth(display, screen);
	rh = DisplayHeight(display, screen);

	if(stretch == 1) {
		w = rw;
		h = rh;
	} else {
		w = im->rgb_width;
		h = im->rgb_height;
	}

	XSelectInput(display, window, StructureNotifyMask);

	Imlib_render(id, im, w, h);

	p = Imlib_move_image(id, im);
	m = Imlib_move_mask(id, im);

	XSetWindowBackgroundPixmap(display, window, p);

	if (m) XShapeCombineMask(display, window, ShapeBounding,
		0, 0, m, ShapeSet);

	XMapWindow(display, window);
	XClearWindow(display, window);

/* Free the buffers that Imlib allocated... */
	Imlib_kill_image(id, im);
	Imlib_free_pixmap(id, p);
	Imlib_free_pixmap(id, m);

	XCloseDisplay(display);
	return 0;
}