File: cursor.c

package info (click to toggle)
treetool 2.0.2-1
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 3,460 kB
  • ctags: 2,692
  • sloc: ansic: 26,504; makefile: 212
file content (121 lines) | stat: -rw-r--r-- 2,040 bytes parent folder | download | duplicates (5)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <stdio.h>

#include <X11/Xlib.h>

#include "generic.h"

typedef struct {
	ltgenericd g;
	Cursor c;
	} ltcursord, *ltcursor;

tcursor tcursor_new(where, w, h, xhot, yhot, sbits, mbits, fg, bg)
titem where;
int w, h, xhot, yhot;
char *sbits;
char *mbits;
tcolor fg, bg;
{
	Display *xdpy;
	tdisplay dpy;
	Pixmap src, msk;
	Drawable win;
	ltcursor c;

	/* check types */
	if(where==NULL || sbits==NULL || mbits==NULL || fg==NULL || bg==NULL)
		return(NULL);
	if(w<=0 || h<=0)
		return(NULL);
	if(xhot<0 || xhot>=w || yhot<0 || yhot>=h)
		return(NULL);
	if(titem_type(fg)!=lt_color ||
			titem_type(bg)!=lt_color)
		return(NULL);

	dpy=(tdisplay)titem_display(where);
	win=(Drawable)titem_drawable(where);
    xdpy=(Display *)tdisplay_X(dpy);

	src=XCreateBitmapFromData(xdpy, win, sbits, w, h);
	if(src==NULL)
		return(NULL);

	msk=XCreateBitmapFromData(xdpy, win, mbits, w, h);
	if(msk==NULL)
	{
		XFreePixmap(xdpy, src);
		return(NULL);
	}

	c=(ltcursor)titem_new(NULL, lt_cursor, sizeof(ltcursord));
	if(c==NULL)
	{
		XFreePixmap(xdpy, src);
		XFreePixmap(xdpy, msk);
		return(NULL);
	}


	c->c=XCreatePixmapCursor(xdpy, src, msk,
		tcolor_Xcolor(fg), tcolor_Xcolor(bg), xhot, yhot);
	XFreePixmap(xdpy, src);
	XFreePixmap(xdpy, msk);
	if(c->c==NULL)
	{
		free(c);
		return(NULL);
	}

	return(c);
}

Cursor tcursor_X(c)
ltcursor c;
{
	if(c==NULL)
		return(NULL);
	if(titem_type(c)!=lt_cursor)
		return(NULL);
	
	return(c->c);
}

int tcursor_set(c, where)
ltcursor c;
titem where;
{
	Display *xdpy;
	tdisplay dpy;
	Window w;

	if(c==NULL || where==NULL)
		return(0);
	if(titem_type(c)!=lt_cursor)
		return(0);

	dpy=(tdisplay)titem_display(where);
	w=(Drawable)titem_drawable(where);
    xdpy=(Display *)tdisplay_X(dpy);

	XDefineCursor(xdpy, w, c->c);
	return(1);
}

int tcursor_unset(where)
titem where;
{
	Display *xdpy;
	tdisplay dpy;
	Window w;

	if(where==NULL)
		return(0);

	dpy=(tdisplay)titem_display(where);
	w=(Drawable)titem_drawable(where);
    xdpy=(Display *)tdisplay_X(dpy);

	XUndefineCursor(xdpy, w);
	return(1);
}