cursor.c revision ffd25bca
1/* 2 * 3Copyright 1989, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 * */ 25 26/*********************************************************************** 27 * 28 * cursor creation code 29 * 30 * 05-Apr-89 Thomas E. LaStrange File created 31 * 32 ***********************************************************************/ 33 34#include <stdio.h> 35#include "twm.h" 36#include <X11/Xos.h> 37#include "screen.h" 38#include "util.h" 39 40static 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 125void 126NewFontCursor (Cursor *cp, char *str) 127{ 128 int i; 129 130 for (i = 0; i < sizeof(cursor_names)/sizeof(struct _CursorName); i++) 131 { 132 if (strcmp(str, cursor_names[i].name) == 0) 133 { 134 if (cursor_names[i].cursor == None) 135 cursor_names[i].cursor = XCreateFontCursor(dpy, 136 cursor_names[i].shape); 137 *cp = cursor_names[i].cursor; 138 return; 139 } 140 } 141 fprintf (stderr, "%s: unable to find font cursor \"%s\"\n", 142 ProgramName, str); 143} 144 145void 146NewBitmapCursor(Cursor *cp, char *source, char *mask) 147{ 148 int hotx, hoty; 149 int sx, sy, mx, my; 150 unsigned int sw, sh, mw, mh; 151 Pixmap spm, mpm; 152 153 spm = GetBitmap(source); 154 if ((hotx = HotX) < 0) hotx = 0; 155 if ((hoty = HotY) < 0) hoty = 0; 156 mpm = GetBitmap(mask); 157 158 /* make sure they are the same size */ 159 160 XGetGeometry(dpy, spm, &JunkRoot, &sx, &sy, &sw, &sh, &JunkBW,&JunkDepth); 161 XGetGeometry(dpy, mpm, &JunkRoot, &mx, &my, &mw, &mh, &JunkBW,&JunkDepth); 162 if (sw != mw || sh != mh) 163 { 164 fprintf (stderr, 165 "%s: cursor bitmaps \"%s\" and \"%s\" not the same size\n", 166 ProgramName, source, mask); 167 return; 168 } 169 *cp = XCreatePixmapCursor(dpy, spm, mpm, &Scr->PointerForeground, 170 &Scr->PointerBackground, hotx,hoty); 171} 172