cursor.c revision 3e747e6d
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/* $XFree86: xc/programs/twm/cursor.c,v 1.4 2001/01/17 23:45:05 dawes Exp $ */ 26 27/*********************************************************************** 28 * 29 * $Xorg: cursor.c,v 1.5 2001/02/09 02:05:36 xorgcvs Exp $ 30 * 31 * cursor creation code 32 * 33 * 05-Apr-89 Thomas E. LaStrange File created 34 * 35 ***********************************************************************/ 36 37#include <stdio.h> 38#include "twm.h" 39#include <X11/Xos.h> 40#include "screen.h" 41#include "util.h" 42 43static struct _CursorName { 44 char *name; 45 unsigned int shape; 46 Cursor cursor; 47} cursor_names[] = { 48 49{"X_cursor", XC_X_cursor, None}, 50{"arrow", XC_arrow, None}, 51{"based_arrow_down", XC_based_arrow_down, None}, 52{"based_arrow_up", XC_based_arrow_up, None}, 53{"boat", XC_boat, None}, 54{"bogosity", XC_bogosity, None}, 55{"bottom_left_corner", XC_bottom_left_corner, None}, 56{"bottom_right_corner", XC_bottom_right_corner, None}, 57{"bottom_side", XC_bottom_side, None}, 58{"bottom_tee", XC_bottom_tee, None}, 59{"box_spiral", XC_box_spiral, None}, 60{"center_ptr", XC_center_ptr, None}, 61{"circle", XC_circle, None}, 62{"clock", XC_clock, None}, 63{"coffee_mug", XC_coffee_mug, None}, 64{"cross", XC_cross, None}, 65{"cross_reverse", XC_cross_reverse, None}, 66{"crosshair", XC_crosshair, None}, 67{"diamond_cross", XC_diamond_cross, None}, 68{"dot", XC_dot, None}, 69{"dotbox", XC_dotbox, None}, 70{"double_arrow", XC_double_arrow, None}, 71{"draft_large", XC_draft_large, None}, 72{"draft_small", XC_draft_small, None}, 73{"draped_box", XC_draped_box, None}, 74{"exchange", XC_exchange, None}, 75{"fleur", XC_fleur, None}, 76{"gobbler", XC_gobbler, None}, 77{"gumby", XC_gumby, None}, 78{"hand1", XC_hand1, None}, 79{"hand2", XC_hand2, None}, 80{"heart", XC_heart, None}, 81{"icon", XC_icon, None}, 82{"iron_cross", XC_iron_cross, None}, 83{"left_ptr", XC_left_ptr, None}, 84{"left_side", XC_left_side, None}, 85{"left_tee", XC_left_tee, None}, 86{"leftbutton", XC_leftbutton, None}, 87{"ll_angle", XC_ll_angle, None}, 88{"lr_angle", XC_lr_angle, None}, 89{"man", XC_man, None}, 90{"middlebutton", XC_middlebutton, None}, 91{"mouse", XC_mouse, None}, 92{"pencil", XC_pencil, None}, 93{"pirate", XC_pirate, None}, 94{"plus", XC_plus, None}, 95{"question_arrow", XC_question_arrow, None}, 96{"right_ptr", XC_right_ptr, None}, 97{"right_side", XC_right_side, None}, 98{"right_tee", XC_right_tee, None}, 99{"rightbutton", XC_rightbutton, None}, 100{"rtl_logo", XC_rtl_logo, None}, 101{"sailboat", XC_sailboat, None}, 102{"sb_down_arrow", XC_sb_down_arrow, None}, 103{"sb_h_double_arrow", XC_sb_h_double_arrow, None}, 104{"sb_left_arrow", XC_sb_left_arrow, None}, 105{"sb_right_arrow", XC_sb_right_arrow, None}, 106{"sb_up_arrow", XC_sb_up_arrow, None}, 107{"sb_v_double_arrow", XC_sb_v_double_arrow, None}, 108{"shuttle", XC_shuttle, None}, 109{"sizing", XC_sizing, None}, 110{"spider", XC_spider, None}, 111{"spraycan", XC_spraycan, None}, 112{"star", XC_star, None}, 113{"target", XC_target, None}, 114{"tcross", XC_tcross, None}, 115{"top_left_arrow", XC_top_left_arrow, None}, 116{"top_left_corner", XC_top_left_corner, None}, 117{"top_right_corner", XC_top_right_corner, None}, 118{"top_side", XC_top_side, None}, 119{"top_tee", XC_top_tee, None}, 120{"trek", XC_trek, None}, 121{"ul_angle", XC_ul_angle, None}, 122{"umbrella", XC_umbrella, None}, 123{"ur_angle", XC_ur_angle, None}, 124{"watch", XC_watch, None}, 125{"xterm", XC_xterm, None}, 126}; 127 128void 129NewFontCursor (Cursor *cp, char *str) 130{ 131 int i; 132 133 for (i = 0; i < sizeof(cursor_names)/sizeof(struct _CursorName); i++) 134 { 135 if (strcmp(str, cursor_names[i].name) == 0) 136 { 137 if (cursor_names[i].cursor == None) 138 cursor_names[i].cursor = XCreateFontCursor(dpy, 139 cursor_names[i].shape); 140 *cp = cursor_names[i].cursor; 141 return; 142 } 143 } 144 fprintf (stderr, "%s: unable to find font cursor \"%s\"\n", 145 ProgramName, str); 146} 147 148void 149NewBitmapCursor(Cursor *cp, char *source, char *mask) 150{ 151 int hotx, hoty; 152 int sx, sy, mx, my; 153 unsigned int sw, sh, mw, mh; 154 Pixmap spm, mpm; 155 156 spm = GetBitmap(source); 157 if ((hotx = HotX) < 0) hotx = 0; 158 if ((hoty = HotY) < 0) hoty = 0; 159 mpm = GetBitmap(mask); 160 161 /* make sure they are the same size */ 162 163 XGetGeometry(dpy, spm, &JunkRoot, &sx, &sy, &sw, &sh, &JunkBW,&JunkDepth); 164 XGetGeometry(dpy, mpm, &JunkRoot, &mx, &my, &mw, &mh, &JunkBW,&JunkDepth); 165 if (sw != mw || sh != mh) 166 { 167 fprintf (stderr, 168 "%s: cursor bitmaps \"%s\" and \"%s\" not the same size\n", 169 ProgramName, source, mask); 170 return; 171 } 172 *cp = XCreatePixmapCursor(dpy, spm, mpm, &Scr->PointerForeground, 173 &Scr->PointerBackground, hotx,hoty); 174} 175