1 /* $Header: /home/yav/catty/fkiss/RCS/cursor.c,v 1.12 2000/08/24 02:14:13 yav Exp $
2  * fkiss cursor font
3  * written by yav <yav@bigfoot.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 char cursor_id[] = "$Id: cursor.c,v 1.12 2000/08/24 02:14:13 yav Exp $";
21 
22 #include <X11/Xos.h>
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25 #include <X11/cursorfont.h>
26 #include <X11/keysym.h>
27 
28 #include "config.h"
29 
30 #include <stdio.h>
31 
32 #include "headers.h"
33 #include "fkiss.h"
34 #include "work.h"
35 
36 #define PUBLIC_CURSOR_C
37 #include "extern.h"
38 
39 #define CUR_Undef	(-1)
40 #define CUR_NULL	0
41 #define CUR_HAND	1
42 #define CUR_GRIP	2
43 #define CUR_ARROW	3
44 #define CUR_CROSS	4
45 #define CUR_FLEUR	5
46 #define MAX_CUR		6
47 
48 typedef struct {
49   Cursor id;
50   Pixmap font;
51   Pixmap mask;
52 } CURSOR_RESOURCE;
53 
54 static CURSOR_RESOURCE *crs = NULL;
55 static unsigned char ptrn_null[] = {
56   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
59 #include "hand0.xbm"
60 #include "hand1.xbm"
61 #include "grip0.xbm"
62 #include "grip1.xbm"
63 
64 /* install cursor resource */
init_cursor()65 void init_cursor()
66 {
67   int i;
68   CURSOR_RESOURCE *p;
69   XColor cfore, cback;
70   static struct {
71     unsigned char *mask;	/* mask pattern bitmap data */
72     unsigned char *font;	/* font pattern bitmap data */
73     int w;			/* bitmap width or X Cursor code */
74     int h;			/* bitmap height */
75     int x, y;			/* hotspot */
76   } ctbl[MAX_CUR] = {
77     {				/* 0:CUR_NULL */
78       ptrn_null, ptrn_null,
79       16, 16, 0, 0},
80     {				/* 1:CUR_HAND */
81       hand0_bits, hand1_bits,
82       hand1_width, hand1_height, hand1_x_hot, hand1_y_hot},
83     {				/* 2:CUR_GRIP */
84       grip0_bits, grip1_bits,
85       grip1_width, grip1_height, grip1_x_hot, grip1_y_hot},
86     {
87       NULL, NULL,
88       XC_top_left_arrow, 0, 0, 0},
89     {
90       NULL, NULL,
91       XC_tcross, 0, 0, 0},
92     {
93       NULL, NULL,
94       XC_fleur, 0, 0, 0}
95   };
96 
97   if (!cursor_mode)
98     return;
99   if (crs == NULL) {
100     crs = (CURSOR_RESOURCE *)ks_malloc(sizeof(CURSOR_RESOURCE)*MAX_CUR);
101     bzero((char *)crs, sizeof(CURSOR_RESOURCE)*MAX_CUR);
102   }
103   XParseColor(dsp, cmap, str_curs_fore, &cfore);
104   XParseColor(dsp, cmap, str_curs_back, &cback);
105   for (p = crs, i = 0; i < MAX_CUR; p++, i++) {
106     if (p->id != None) {
107       XFreeCursor(dsp, p->id);
108       p->id = None;
109     }
110     if (p->mask != None) {
111       XFreePixmap(dsp, p->mask);
112       p->mask = None;
113     }
114     if (p->font != None) {
115       XFreePixmap(dsp, p->font);
116       p->font = None;
117     }
118     if (ctbl[i].mask != NULL) {
119       p->mask =
120 	XCreateBitmapFromData(dsp, rootwin, ctbl[i].mask,
121 			      ctbl[i].w, ctbl[i].h);
122       p->font =
123 	XCreateBitmapFromData(dsp, rootwin, ctbl[i].font,
124 			      ctbl[i].w, ctbl[i].h);
125       p->id = XCreatePixmapCursor(dsp, p->font, p->mask,
126 				  &cfore, &cback,
127 				  ctbl[i].x, ctbl[i].y);
128     } else {
129       p->id = XCreateFontCursor(dsp, ctbl[i].w);
130     }
131   }
132 }
133 
134 /* install cursor font */
cursor_set(win,n)135 void cursor_set(win, n)
136      Window win;
137      int n;
138 {
139   if (n == CUR_Undef)
140     XUndefineCursor(dsp, win);
141   else
142     XDefineCursor(dsp, win, (crs+n)->id);
143 }
144 
set_cursor(n)145 void set_cursor(n)
146      int n;
147 {
148   if (cursor_mode)
149     cursor_set(viewwin, n);
150 }
151 
cursor_grip()152 void cursor_grip()
153 {
154   set_cursor((cursor_mode & 2) ? CUR_GRIP : CUR_NULL);
155 }
156 
cursor_hand()157 void cursor_hand()
158 {
159   set_cursor((cursor_mode & 1) ? CUR_HAND : CUR_Undef);
160 }
161 
cursor_scroll()162 void cursor_scroll()
163 {
164   set_cursor(CUR_FLEUR);
165 }
166 
167 /* End of file */
168