chiark / gitweb /
Import vtwm_5.4.7.orig.tar.gz
[vtwm.git] / cursor.c
1 /*
2  * Copyright 1989 Massachusetts Institute of Technology
3  *
4  * Permission to use, copy, modify, and distribute this software and its
5  * documentation for any purpose and without fee is hereby granted, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of M.I.T. not be used in advertising
9  * or publicity pertaining to distribution of the software without specific,
10  * written prior permission.  M.I.T. makes no representations about the
11  * suitability of this software for any purpose.  It is provided "as is"
12  * without express or implied warranty.
13  *
14  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
16  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
19  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21
22 /***********************************************************************
23  *
24  * $XConsortium: cursor.c,v 1.10 89/12/14 14:52:23 jim Exp $
25  *
26  * cursor creation code
27  *
28  * 05-Apr-89 Thomas E. LaStrange        File created
29  *
30  ***********************************************************************/
31
32 #include <stdio.h>
33 #include "twm.h"
34 #include <X11/Xos.h>
35 #include "screen.h"
36 #include "util.h"
37
38 void NewBitmapCursor();
39
40 static struct _CursorName {
41     char                *name;
42     unsigned int        shape;
43     Cursor              cursor;
44 } cursor_names[] = {
45
46 {"X_cursor",            XC_X_cursor,            None},
47 {"arrow",               XC_arrow,               None},
48 {"based_arrow_down",    XC_based_arrow_down,    None},
49 {"based_arrow_up",      XC_based_arrow_up,      None},
50 {"boat",                XC_boat,                None},
51 {"bogosity",            XC_bogosity,            None},
52 {"bottom_left_corner",  XC_bottom_left_corner,  None},
53 {"bottom_right_corner", XC_bottom_right_corner, None},
54 {"bottom_side",         XC_bottom_side,         None},
55 {"bottom_tee",          XC_bottom_tee,          None},
56 {"box_spiral",          XC_box_spiral,          None},
57 {"center_ptr",          XC_center_ptr,          None},
58 {"circle",              XC_circle,              None},
59 {"clock",               XC_clock,               None},
60 {"coffee_mug",          XC_coffee_mug,          None},
61 {"cross",               XC_cross,               None},
62 {"cross_reverse",       XC_cross_reverse,       None},
63 {"crosshair",           XC_crosshair,           None},
64 {"diamond_cross",       XC_diamond_cross,       None},
65 {"dot",                 XC_dot,                 None},
66 {"dotbox",              XC_dotbox,              None},
67 {"double_arrow",        XC_double_arrow,        None},
68 {"draft_large",         XC_draft_large,         None},
69 {"draft_small",         XC_draft_small,         None},
70 {"draped_box",          XC_draped_box,          None},
71 {"exchange",            XC_exchange,            None},
72 {"fleur",               XC_fleur,               None},
73 {"gobbler",             XC_gobbler,             None},
74 {"gumby",               XC_gumby,               None},
75 {"hand1",               XC_hand1,               None},
76 {"hand2",               XC_hand2,               None},
77 {"heart",               XC_heart,               None},
78 {"icon",                XC_icon,                None},
79 {"iron_cross",          XC_iron_cross,          None},
80 {"left_ptr",            XC_left_ptr,            None},
81 {"left_side",           XC_left_side,           None},
82 {"left_tee",            XC_left_tee,            None},
83 {"leftbutton",          XC_leftbutton,          None},
84 {"ll_angle",            XC_ll_angle,            None},
85 {"lr_angle",            XC_lr_angle,            None},
86 {"man",                 XC_man,                 None},
87 {"middlebutton",        XC_middlebutton,        None},
88 {"mouse",               XC_mouse,               None},
89 {"pencil",              XC_pencil,              None},
90 {"pirate",              XC_pirate,              None},
91 {"plus",                XC_plus,                None},
92 {"question_arrow",      XC_question_arrow,      None},
93 {"right_ptr",           XC_right_ptr,           None},
94 {"right_side",          XC_right_side,          None},
95 {"right_tee",           XC_right_tee,           None},
96 {"rightbutton",         XC_rightbutton,         None},
97 {"rtl_logo",            XC_rtl_logo,            None},
98 {"sailboat",            XC_sailboat,            None},
99 {"sb_down_arrow",       XC_sb_down_arrow,       None},
100 {"sb_h_double_arrow",   XC_sb_h_double_arrow,   None},
101 {"sb_left_arrow",       XC_sb_left_arrow,       None},
102 {"sb_right_arrow",      XC_sb_right_arrow,      None},
103 {"sb_up_arrow",         XC_sb_up_arrow,         None},
104 {"sb_v_double_arrow",   XC_sb_v_double_arrow,   None},
105 {"shuttle",             XC_shuttle,             None},
106 {"sizing",              XC_sizing,              None},
107 {"spider",              XC_spider,              None},
108 {"spraycan",            XC_spraycan,            None},
109 {"star",                XC_star,                None},
110 {"target",              XC_target,              None},
111 {"tcross",              XC_tcross,              None},
112 {"top_left_arrow",      XC_top_left_arrow,      None},
113 {"top_left_corner",     XC_top_left_corner,     None},
114 {"top_right_corner",    XC_top_right_corner,    None},
115 {"top_side",            XC_top_side,            None},
116 {"top_tee",             XC_top_tee,             None},
117 {"trek",                XC_trek,                None},
118 {"ul_angle",            XC_ul_angle,            None},
119 {"umbrella",            XC_umbrella,            None},
120 {"ur_angle",            XC_ur_angle,            None},
121 {"watch",               XC_watch,               None},
122 {"xterm",               XC_xterm,               None},
123 };
124
125 void NewFontCursor (cp, str)
126     Cursor *cp;
127     char *str;
128 {
129     int i;
130
131     for (i = 0; i < sizeof(cursor_names)/sizeof(struct _CursorName); i++)
132     {
133         if (strcmp(str, cursor_names[i].name) == 0)
134         {
135             if (cursor_names[i].cursor == None)
136                 cursor_names[i].cursor = XCreateFontCursor(dpy,
137                         cursor_names[i].shape);
138             *cp = cursor_names[i].cursor;
139             return;
140         }
141     }
142     fprintf (stderr, "%s:  unable to find font cursor \"%s\"\n", 
143              ProgramName, str);
144 }
145
146 void NewBitmapCursor(cp, source, mask)
147 Cursor *cp;
148 char *source, *mask;
149 {
150     XColor fore, back;
151     int hotx, hoty;
152     int sx, sy, mx, my;
153     unsigned int sw, sh, mw, mh;
154     Pixmap spm, mpm;
155     Colormap cmap = Scr->TwmRoot.cmaps.cwins[0]->colormap->c;
156
157     fore.pixel = Scr->Black;
158     XQueryColor(dpy, cmap, &fore);
159     back.pixel = Scr->White;
160     XQueryColor(dpy, cmap, &back);
161
162     spm = GetBitmap(source);
163     if ((hotx = HotX) < 0) hotx = 0;
164     if ((hoty = HotY) < 0) hoty = 0;
165     mpm = GetBitmap(mask);
166
167     /* make sure they are the same size */
168
169     XGetGeometry(dpy, spm, &JunkRoot, &sx, &sy, &sw, &sh, &JunkBW,&JunkDepth);
170     XGetGeometry(dpy, mpm, &JunkRoot, &mx, &my, &mw, &mh, &JunkBW,&JunkDepth);
171     if (sw != mw || sh != mh)
172     {
173         fprintf (stderr, 
174                  "%s:  cursor bitmaps \"%s\" and \"%s\" not the same size\n",
175                  ProgramName, source, mask);
176         return;
177     }
178     *cp = XCreatePixmapCursor(dpy, spm, mpm, &fore, &back, hotx,hoty);
179 }