diff options
-rw-r--r-- | oneko.c | 1154 | ||||
-rw-r--r-- | oneko.h | 84 |
2 files changed, 619 insertions, 619 deletions
diff --git a/oneko.c b/oneko.c index de54c1e..36fe424 100644 --- a/oneko.c +++ b/oneko.c @@ -1,35 +1,35 @@ /* - * oneko - X11 猫 + * oneko - X11 猫 */ -#ifndef lint +#ifndef lint static char rcsid[] = "$Header: /home/sun/unix/kato/xsam/oneko/oneko.c,v 1.5 90/10/19 21:25:16 kato Exp $"; #endif #include "oneko.h" #include "patchlevel.h" /* - * グローバル変数 + * グローバル変数 */ -char *ClassName = "Oneko"; /* コマンド名称 */ -char *ProgramName; /* コマンド名称 */ +char *ClassName = "Oneko"; /* コマンド名称 */ +char *ProgramName; /* コマンド名称 */ -Display *theDisplay; /* ディスプレイ構造体 */ -int theScreen; /* スクリーン番号 */ -unsigned int theDepth; /* デプス */ -Window theRoot; /* ルートウィンドウのID */ -Window theWindow; /* 猫ウィンドウのID */ -char *WindowName = NULL; /* 猫ウィンドウの名前 */ -Window theTarget = None; /* 目標ウィンドウのID */ -char *TargetName = NULL; /* 目標ウィンドウの名前 */ -Cursor theCursor; /* ねずみカーソル */ +Display *theDisplay; /* ディスプレイ構造体 */ +int theScreen; /* スクリーン番号 */ +unsigned int theDepth; /* デプス */ +Window theRoot; /* ルートウィンドウのID */ +Window theWindow; /* 猫ウィンドウのID */ +char *WindowName = NULL; /* 猫ウィンドウの名前 */ +Window theTarget = None; /* 目標ウィンドウのID */ +char *TargetName = NULL; /* 目標ウィンドウの名前 */ +Cursor theCursor; /* ねずみカーソル */ -unsigned int WindowWidth; /* ルートウィンドウの幅 */ -unsigned int WindowHeight; /* ルートウィンドウの高さ */ +unsigned int WindowWidth; /* ルートウィンドウの幅 */ +unsigned int WindowHeight; /* ルートウィンドウの高さ */ -XColor theForegroundColor; /* 色 (フォアグラウンド) */ -XColor theBackgroundColor; /* 色 (バックグラウンド) */ +XColor theForegroundColor; /* 色 (フォアグラウンド) */ +XColor theBackgroundColor; /* 色 (バックグラウンド) */ int Synchronous = False; /* Types of animals */ @@ -60,99 +60,99 @@ AnimalDefaultsData AnimalDefaultsDataTable[] = }; /* - * いろいろな初期設定 (オプション、リソースで変えられるよ) + * いろいろな初期設定 (オプション、リソースで変えられるよ) */ - /* Resource: */ -char *Foreground = NULL; /* foreground */ -char *Background = NULL; /* background */ -long IntervalTime = 0L; /* time */ -double NekoSpeed = (double)0; /* speed */ -int IdleSpace = 0; /* idle */ -int NekoMoyou = NOTDEFINED; /* tora */ -int NoShape = NOTDEFINED; /* noshape */ -int ReverseVideo = NOTDEFINED; /* reverse */ -int ToWindow = NOTDEFINED; /* towindow */ -int ToFocus = NOTDEFINED; /* tofocus */ + /* Resource: */ +char *Foreground = NULL; /* foreground */ +char *Background = NULL; /* background */ +long IntervalTime = 0L; /* time */ +double NekoSpeed = (double)0; /* speed */ +int IdleSpace = 0; /* idle */ +int NekoMoyou = NOTDEFINED; /* tora */ +int NoShape = NOTDEFINED; /* noshape */ +int ReverseVideo = NOTDEFINED; /* reverse */ +int ToWindow = NOTDEFINED; /* towindow */ +int ToFocus = NOTDEFINED; /* tofocus */ int XOffset=0,YOffset=0; /* X and Y offsets for cat from mouse - pointer. */ + pointer. */ /* - * いろいろな状態変数 + * いろいろな状態変数 */ -Bool DontMapped = True; +Bool DontMapped = True; -int NekoTickCount; /* 猫動作カウンタ */ -int NekoStateCount; /* 猫同一状態カウンタ */ -int NekoState; /* 猫の状態 */ +int NekoTickCount; /* 猫動作カウンタ */ +int NekoStateCount; /* 猫同一状態カウンタ */ +int NekoState; /* 猫の状態 */ -int MouseX; /* マウスX座標 */ -int MouseY; /* マウスY座標 */ +int MouseX; /* マウスX座標 */ +int MouseY; /* マウスY座標 */ -int PrevMouseX = 0; /* 直前のマウスX座標 */ -int PrevMouseY = 0; /* 直前のマウスY座標 */ -Window PrevTarget = None; /* 直前の目標ウィンドウのID */ +int PrevMouseX = 0; /* 直前のマウスX座標 */ +int PrevMouseY = 0; /* 直前のマウスY座標 */ +Window PrevTarget = None; /* 直前の目標ウィンドウのID */ -int NekoX; /* 猫X座標 */ -int NekoY; /* 猫Y座標 */ +int NekoX; /* 猫X座標 */ +int NekoY; /* 猫Y座標 */ -int NekoMoveDx; /* 猫移動距離X */ -int NekoMoveDy; /* 猫移動距離Y */ +int NekoMoveDx; /* 猫移動距離X */ +int NekoMoveDy; /* 猫移動距離Y */ -int NekoLastX; /* 猫最終描画X座標 */ -int NekoLastY; /* 猫最終描画Y座標 */ -GC NekoLastGC; /* 猫最終描画 GC */ +int NekoLastX; /* 猫最終描画X座標 */ +int NekoLastY; /* 猫最終描画Y座標 */ +GC NekoLastGC; /* 猫最終描画 GC */ /* Variables used to set how quickly the program will chose to raise itself. */ /* Look at Interval(), Handle Visiblility Notify Event */ #define DEFAULT_RAISE_WAIT 16 /* About 2 seconds with default interval */ int RaiseWindowDelay=0; /* - * その他 + * その他 */ -double SinPiPer8Times3; /* sin(3π/8) */ -double SinPiPer8; /* sin(π/8) */ +double SinPiPer8Times3; /* sin(3π/8) */ +double SinPiPer8; /* sin(π/8) */ -Pixmap Mati2Xbm, Jare2Xbm, Kaki1Xbm, Kaki2Xbm, Mati3Xbm, Sleep1Xbm, Sleep2Xbm; -Pixmap Mati2Msk, Jare2Msk, Kaki1Msk, Kaki2Msk, Mati3Msk, Sleep1Msk, Sleep2Msk; +Pixmap Mati2Xbm, Jare2Xbm, Kaki1Xbm, Kaki2Xbm, Mati3Xbm, Sleep1Xbm, Sleep2Xbm; +Pixmap Mati2Msk, Jare2Msk, Kaki1Msk, Kaki2Msk, Mati3Msk, Sleep1Msk, Sleep2Msk; -Pixmap AwakeXbm, AwakeMsk; +Pixmap AwakeXbm, AwakeMsk; -Pixmap Up1Xbm, Up2Xbm, Down1Xbm, Down2Xbm, Left1Xbm, Left2Xbm; -Pixmap Up1Msk, Up2Msk, Down1Msk, Down2Msk, Left1Msk, Left2Msk; -Pixmap Right1Xbm, Right2Xbm, UpLeft1Xbm, UpLeft2Xbm, UpRight1Xbm; -Pixmap Right1Msk, Right2Msk, UpLeft1Msk, UpLeft2Msk, UpRight1Msk; -Pixmap UpRight2Xbm, DownLeft1Xbm, DownLeft2Xbm, DownRight1Xbm, DownRight2Xbm; -Pixmap UpRight2Msk, DownLeft1Msk, DownLeft2Msk, DownRight1Msk, DownRight2Msk; +Pixmap Up1Xbm, Up2Xbm, Down1Xbm, Down2Xbm, Left1Xbm, Left2Xbm; +Pixmap Up1Msk, Up2Msk, Down1Msk, Down2Msk, Left1Msk, Left2Msk; +Pixmap Right1Xbm, Right2Xbm, UpLeft1Xbm, UpLeft2Xbm, UpRight1Xbm; +Pixmap Right1Msk, Right2Msk, UpLeft1Msk, UpLeft2Msk, UpRight1Msk; +Pixmap UpRight2Xbm, DownLeft1Xbm, DownLeft2Xbm, DownRight1Xbm, DownRight2Xbm; +Pixmap UpRight2Msk, DownLeft1Msk, DownLeft2Msk, DownRight1Msk, DownRight2Msk; -Pixmap UpTogi1Xbm, UpTogi2Xbm, DownTogi1Xbm, DownTogi2Xbm, LeftTogi1Xbm; -Pixmap UpTogi1Msk, UpTogi2Msk, DownTogi1Msk, DownTogi2Msk, LeftTogi1Msk; -Pixmap LeftTogi2Xbm, RightTogi1Xbm, RightTogi2Xbm; -Pixmap LeftTogi2Msk, RightTogi1Msk, RightTogi2Msk; +Pixmap UpTogi1Xbm, UpTogi2Xbm, DownTogi1Xbm, DownTogi2Xbm, LeftTogi1Xbm; +Pixmap UpTogi1Msk, UpTogi2Msk, DownTogi1Msk, DownTogi2Msk, LeftTogi1Msk; +Pixmap LeftTogi2Xbm, RightTogi1Xbm, RightTogi2Xbm; +Pixmap LeftTogi2Msk, RightTogi1Msk, RightTogi2Msk; GC Mati2GC; -GC Jare2GC, Kaki1GC, Kaki2GC, Mati3GC, Sleep1GC, Sleep2GC; +GC Jare2GC, Kaki1GC, Kaki2GC, Mati3GC, Sleep1GC, Sleep2GC; -GC AwakeGC; +GC AwakeGC; -GC Up1GC, Up2GC, Down1GC, Down2GC, Left1GC, Left2GC, Right1GC, Right2GC; -GC UpLeft1GC, UpLeft2GC, UpRight1GC, UpRight2GC, DownLeft1GC, DownLeft2GC; -GC DownRight1GC, DownRight2GC; +GC Up1GC, Up2GC, Down1GC, Down2GC, Left1GC, Left2GC, Right1GC, Right2GC; +GC UpLeft1GC, UpLeft2GC, UpRight1GC, UpRight2GC, DownLeft1GC, DownLeft2GC; +GC DownRight1GC, DownRight2GC; -GC UpTogi1GC, UpTogi2GC, DownTogi1GC, DownTogi2GC, LeftTogi1GC; -GC LeftTogi2GC, RightTogi1GC, RightTogi2GC; +GC UpTogi1GC, UpTogi2GC, DownTogi1GC, DownTogi2GC, LeftTogi1GC; +GC LeftTogi2GC, RightTogi1GC, RightTogi2GC; typedef struct { - GC *GCCreatePtr; - Pixmap *BitmapCreatePtr; - char *PixelPattern[BITMAPTYPES]; - Pixmap *BitmapMasksPtr; - char *MaskPattern[BITMAPTYPES]; + GC *GCCreatePtr; + Pixmap *BitmapCreatePtr; + char *PixelPattern[BITMAPTYPES]; + Pixmap *BitmapMasksPtr; + char *MaskPattern[BITMAPTYPES]; } BitmapGCData; -BitmapGCData BitmapGCDataTable[] = +BitmapGCData BitmapGCDataTable[] = { { &Mati2GC, &Mati2Xbm, mati2_bits, mati2_tora_bits, mati2_dog_bits, mati2_bsd_bits, mati2_sakura_bits, mati2_tomoyo_bits, &Mati2Msk, mati2_mask_bits, mati2_mask_bits, mati2_dog_mask_bits, mati2_bsd_mask_bits, mati2_sakura_mask_bits, mati2_tomoyo_mask_bits }, @@ -222,61 +222,61 @@ BitmapGCData BitmapGCDataTable[] = }; typedef struct { - GC *TickGCPtr; - Pixmap *TickMaskPtr; + GC *TickGCPtr; + Pixmap *TickMaskPtr; } Animation; -Animation AnimationPattern[][2] = +Animation AnimationPattern[][2] = { { { &Mati2GC, &Mati2Msk }, - { &Mati2GC, &Mati2Msk } }, /* NekoState == NEKO_STOP */ + { &Mati2GC, &Mati2Msk } }, /* NekoState == NEKO_STOP */ { { &Jare2GC, &Jare2Msk }, - { &Mati2GC, &Mati2Msk } }, /* NekoState == NEKO_JARE */ + { &Mati2GC, &Mati2Msk } }, /* NekoState == NEKO_JARE */ { { &Kaki1GC, &Kaki1Msk }, - { &Kaki2GC, &Kaki2Msk } }, /* NekoState == NEKO_KAKI */ + { &Kaki2GC, &Kaki2Msk } }, /* NekoState == NEKO_KAKI */ { { &Mati3GC, &Mati3Msk }, - { &Mati3GC, &Mati3Msk } }, /* NekoState == NEKO_AKUBI */ + { &Mati3GC, &Mati3Msk } }, /* NekoState == NEKO_AKUBI */ { { &Sleep1GC, &Sleep1Msk }, - { &Sleep2GC, &Sleep2Msk } }, /* NekoState == NEKO_SLEEP */ + { &Sleep2GC, &Sleep2Msk } }, /* NekoState == NEKO_SLEEP */ { { &AwakeGC, &AwakeMsk }, - { &AwakeGC, &AwakeMsk } }, /* NekoState == NEKO_AWAKE */ + { &AwakeGC, &AwakeMsk } }, /* NekoState == NEKO_AWAKE */ { { &Up1GC, &Up1Msk }, - { &Up2GC, &Up2Msk } }, /* NekoState == NEKO_U_MOVE */ + { &Up2GC, &Up2Msk } }, /* NekoState == NEKO_U_MOVE */ { { &Down1GC, &Down1Msk }, - { &Down2GC, &Down2Msk } }, /* NekoState == NEKO_D_MOVE */ + { &Down2GC, &Down2Msk } }, /* NekoState == NEKO_D_MOVE */ { { &Left1GC, &Left1Msk }, - { &Left2GC, &Left2Msk } }, /* NekoState == NEKO_L_MOVE */ + { &Left2GC, &Left2Msk } }, /* NekoState == NEKO_L_MOVE */ { { &Right1GC, &Right1Msk }, - { &Right2GC, &Right2Msk } }, /* NekoState == NEKO_R_MOVE */ + { &Right2GC, &Right2Msk } }, /* NekoState == NEKO_R_MOVE */ { { &UpLeft1GC, &UpLeft1Msk }, - { &UpLeft2GC, &UpLeft2Msk } }, /* NekoState == NEKO_UL_MOVE */ + { &UpLeft2GC, &UpLeft2Msk } }, /* NekoState == NEKO_UL_MOVE */ { { &UpRight1GC, &UpRight1Msk }, - { &UpRight2GC, &UpRight2Msk } }, /* NekoState == NEKO_UR_MOVE */ + { &UpRight2GC, &UpRight2Msk } }, /* NekoState == NEKO_UR_MOVE */ { { &DownLeft1GC, &DownLeft1Msk }, - { &DownLeft2GC, &DownLeft2Msk } }, /* NekoState == NEKO_DL_MOVE */ + { &DownLeft2GC, &DownLeft2Msk } }, /* NekoState == NEKO_DL_MOVE */ { { &DownRight1GC, &DownRight1Msk }, - { &DownRight2GC, &DownRight2Msk } }, /* NekoState == NEKO_DR_MOVE */ + { &DownRight2GC, &DownRight2Msk } }, /* NekoState == NEKO_DR_MOVE */ { { &UpTogi1GC, &UpTogi1Msk }, - { &UpTogi2GC, &UpTogi2Msk } }, /* NekoState == NEKO_U_TOGI */ + { &UpTogi2GC, &UpTogi2Msk } }, /* NekoState == NEKO_U_TOGI */ { { &DownTogi1GC, &DownTogi1Msk }, - { &DownTogi2GC, &DownTogi2Msk } }, /* NekoState == NEKO_D_TOGI */ + { &DownTogi2GC, &DownTogi2Msk } }, /* NekoState == NEKO_D_TOGI */ { { &LeftTogi1GC, &LeftTogi1Msk }, - { &LeftTogi2GC, &LeftTogi2Msk } }, /* NekoState == NEKO_L_TOGI */ + { &LeftTogi2GC, &LeftTogi2Msk } }, /* NekoState == NEKO_L_TOGI */ { { &RightTogi1GC, &RightTogi1Msk }, - { &RightTogi2GC, &RightTogi2Msk } }, /* NekoState == NEKO_R_TOGI */ + { &RightTogi2GC, &RightTogi2Msk } }, /* NekoState == NEKO_R_TOGI */ }; static void NullFunction(); /* - * ビットマップデータ・GC 初期化 + * ビットマップデータ・GC 初期化 */ void InitBitmapAndGCs() { - BitmapGCData *BitmapGCDataTablePtr; - XGCValues theGCValues; + BitmapGCData *BitmapGCDataTablePtr; + XGCValues theGCValues; theGCValues.function = GXcopy; theGCValues.foreground = theForegroundColor.pixel; @@ -286,59 +286,59 @@ InitBitmapAndGCs() theGCValues.ts_y_origin = 0; for (BitmapGCDataTablePtr = BitmapGCDataTable; - BitmapGCDataTablePtr->GCCreatePtr != NULL; - BitmapGCDataTablePtr++) { - - *(BitmapGCDataTablePtr->BitmapCreatePtr) - = XCreatePixmapFromBitmapData(theDisplay, theRoot, - BitmapGCDataTablePtr->PixelPattern[NekoMoyou], - BITMAP_WIDTH, BITMAP_HEIGHT, - theForegroundColor.pixel, - theBackgroundColor.pixel, - DefaultDepth(theDisplay, theScreen)); - - theGCValues.tile = *(BitmapGCDataTablePtr->BitmapCreatePtr); - - *(BitmapGCDataTablePtr->BitmapMasksPtr) - = XCreateBitmapFromData(theDisplay, theRoot, - BitmapGCDataTablePtr->MaskPattern[NekoMoyou], - BITMAP_WIDTH, BITMAP_HEIGHT); - - *(BitmapGCDataTablePtr->GCCreatePtr) - = XCreateGC(theDisplay, theWindow, - GCFunction | GCForeground | GCBackground | GCTile | - GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, - &theGCValues); + BitmapGCDataTablePtr->GCCreatePtr != NULL; + BitmapGCDataTablePtr++) { + + *(BitmapGCDataTablePtr->BitmapCreatePtr) + = XCreatePixmapFromBitmapData(theDisplay, theRoot, + BitmapGCDataTablePtr->PixelPattern[NekoMoyou], + BITMAP_WIDTH, BITMAP_HEIGHT, + theForegroundColor.pixel, + theBackgroundColor.pixel, + DefaultDepth(theDisplay, theScreen)); + + theGCValues.tile = *(BitmapGCDataTablePtr->BitmapCreatePtr); + + *(BitmapGCDataTablePtr->BitmapMasksPtr) + = XCreateBitmapFromData(theDisplay, theRoot, + BitmapGCDataTablePtr->MaskPattern[NekoMoyou], + BITMAP_WIDTH, BITMAP_HEIGHT); + + *(BitmapGCDataTablePtr->GCCreatePtr) + = XCreateGC(theDisplay, theWindow, + GCFunction | GCForeground | GCBackground | GCTile | + GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, + &theGCValues); } } /* - * リソース・データベースから必要なリソースを取り出す + * リソース・データベースから必要なリソースを取り出す */ -char * +char * NekoGetDefault(resource) -char *resource; +char *resource; { - char *value; - - if (value = XGetDefault(theDisplay, ProgramName, resource)) { - return value; - } - if (value = XGetDefault(theDisplay, ClassName, resource)) { - return value; - } - return NULL; + char *value; + + if (value = XGetDefault(theDisplay, ProgramName, resource)) { + return value; + } + if (value = XGetDefault(theDisplay, ClassName, resource)) { + return value; + } + return NULL; } /* - * リソース・データベースからオプションを設定 + * リソース・データベースからオプションを設定 */ GetResources() { - char *resource; - int num; + char *resource; + int num; int loop; if (Foreground == NULL) { if ((resource = NekoGetDefault("foreground")) != NULL) { @@ -355,7 +355,7 @@ GetResources() if (IntervalTime == 0) { if ((resource = NekoGetDefault("time")) != NULL) { if (num = atoi(resource)) { - IntervalTime = num; + IntervalTime = num; } } } @@ -363,7 +363,7 @@ GetResources() if (NekoSpeed == (double)0) { if ((resource = NekoGetDefault("speed")) != NULL) { if (num = atoi(resource)) { - NekoSpeed = (double)num; + NekoSpeed = (double)num; } } } @@ -371,7 +371,7 @@ GetResources() if (IdleSpace == 0) { if ((resource = NekoGetDefault("idle")) != NULL) { if (num = atoi(resource)) { - IdleSpace = num; + IdleSpace = num; } } } @@ -379,8 +379,8 @@ GetResources() if (NekoMoyou == NOTDEFINED) { for (loop=0;loop<BITMAPTYPES;loop++) if ((resource = NekoGetDefault(AnimalDefaultsDataTable[loop].name)) != NULL) { - if (IsTrue(resource)) - NekoMoyou = loop; + if (IsTrue(resource)) + NekoMoyou = loop; } } @@ -431,70 +431,70 @@ GetResources() } /* - * ねずみ型カーソルを作る + * ねずみ型カーソルを作る */ MakeMouseCursor() { - Pixmap theCursorSource; - Pixmap theCursorMask; + Pixmap theCursorSource; + Pixmap theCursorMask; theCursorSource - = XCreateBitmapFromData(theDisplay, theRoot, - AnimalDefaultsDataTable[NekoMoyou].cursor, - AnimalDefaultsDataTable[NekoMoyou].cursor_width, - AnimalDefaultsDataTable[NekoMoyou].cursor_height); + = XCreateBitmapFromData(theDisplay, theRoot, + AnimalDefaultsDataTable[NekoMoyou].cursor, + AnimalDefaultsDataTable[NekoMoyou].cursor_width, + AnimalDefaultsDataTable[NekoMoyou].cursor_height); theCursorMask - = XCreateBitmapFromData(theDisplay, theRoot, - AnimalDefaultsDataTable[NekoMoyou].mask, - AnimalDefaultsDataTable[NekoMoyou].cursor_width, - AnimalDefaultsDataTable[NekoMoyou].cursor_height); + = XCreateBitmapFromData(theDisplay, theRoot, + AnimalDefaultsDataTable[NekoMoyou].mask, + AnimalDefaultsDataTable[NekoMoyou].cursor_width, + AnimalDefaultsDataTable[NekoMoyou].cursor_height); theCursor = XCreatePixmapCursor(theDisplay, theCursorSource, theCursorMask, - &theBackgroundColor, &theForegroundColor, - AnimalDefaultsDataTable[NekoMoyou].cursor_x_hot, - AnimalDefaultsDataTable[NekoMoyou].cursor_y_hot); + &theBackgroundColor, &theForegroundColor, + AnimalDefaultsDataTable[NekoMoyou].cursor_x_hot, + AnimalDefaultsDataTable[NekoMoyou].cursor_y_hot); XFreePixmap(theDisplay,theCursorSource); XFreePixmap(theDisplay,theCursorMask); } /* - * 色を初期設定する + * 色を初期設定する */ SetupColors() { - XColor theExactColor; - Colormap theColormap; + XColor theExactColor; + Colormap theColormap; theColormap = DefaultColormap(theDisplay, theScreen); if (theDepth == 1) { - Foreground = "black"; - Background = "white"; + Foreground = "black"; + Background = "white"; } if (ReverseVideo == True) { - char *tmp; + char *tmp; - tmp = Foreground; - Foreground = Background; - Background = tmp; + tmp = Foreground; + Foreground = Background; + Background = tmp; } if (!XAllocNamedColor(theDisplay, theColormap, - Foreground, &theForegroundColor, &theExactColor)) { - fprintf(stderr, "%s: Can't XAllocNamedColor(\"%s\").\n", - ProgramName, Foreground); - exit(1); + Foreground, &theForegroundColor, &theExactColor)) { + fprintf(stderr, "%s: Can't XAllocNamedColor(\"%s\").\n", + ProgramName, Foreground); + exit(1); } if (!XAllocNamedColor(theDisplay, theColormap, - Background, &theBackgroundColor, &theExactColor)) { - fprintf(stderr, "%s: Can't XAllocNamedColor(\"%s\").\n", - ProgramName, Background); - exit(1); + Background, &theBackgroundColor, &theExactColor)) { + fprintf(stderr, "%s: Can't XAllocNamedColor(\"%s\").\n", + ProgramName, Background); + exit(1); } } @@ -518,8 +518,8 @@ Window Select_Window(dpy) /* Grab the pointer using target cursor, letting it room all over */ status = XGrabPointer(dpy, root, False, - ButtonPressMask|ButtonReleaseMask, GrabModeSync, - GrabModeAsync, root, cursor, CurrentTime); + ButtonPressMask|ButtonReleaseMask, GrabModeSync, + GrabModeAsync, root, cursor, CurrentTime); if (status != GrabSuccess) { fprintf(stderr, "%s: Can't grab the mouse.\n", ProgramName); exit(1); @@ -533,14 +533,14 @@ Window Select_Window(dpy) switch (event.type) { case ButtonPress: if (target_win == None) { - target_win = event.xbutton.subwindow; /* window selected */ - if (target_win == None) target_win = root; + target_win = event.xbutton.subwindow; /* window selected */ + if (target_win == None) target_win = root; } buttons++; break; case ButtonRelease: if (buttons > 0) /* there may have been some down before we started */ - buttons--; + buttons--; break; } } @@ -564,42 +564,42 @@ Window Window_With_Name(dpy, top, name) Window top; char *name; { - Window *children, dummy; - unsigned int nchildren; - int i; - Window w=0; - char *window_name; - - if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name)) - return(top); - - if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren)) - return(0); - - for (i=0; i<nchildren; i++) { - w = Window_With_Name(dpy, children[i], name); - if (w) - break; - } - if (children) XFree ((char *)children); - return(w); + Window *children, dummy; + unsigned int nchildren; + int i; + Window w=0; + char *window_name; + + if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name)) + return(top); + + if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren)) + return(0); + + for (i=0; i<nchildren; i++) { + w = Window_With_Name(dpy, children[i], name); + if (w) + break; + } + if (children) XFree ((char *)children); + return(w); } /* - * スクリーン環境初期化 + * スクリーン環境初期化 */ void InitScreen(DisplayName) - char *DisplayName; + char *DisplayName; { - XSetWindowAttributes theWindowAttributes; - unsigned long theWindowMask; - Window theTempRoot; - int WindowPointX; - int WindowPointY; - unsigned int BorderWidth; - int event_base, error_base; + XSetWindowAttributes theWindowAttributes; + unsigned long theWindowMask; + Window theTempRoot; + int WindowPointX; + int WindowPointY; + unsigned int BorderWidth; + int event_base, error_base; if ((theDisplay = XOpenDisplay(DisplayName)) == NULL) { fprintf(stderr, "%s: Can't open display", ProgramName); @@ -620,10 +620,10 @@ InitScreen(DisplayName) #ifdef SHAPE if (!NoShape && XShapeQueryExtension(theDisplay, - &event_base, &error_base) == False) { + &event_base, &error_base) == False) { fprintf(stderr, "Display not suported shape extension.\n"); NoShape = True; - } + } #endif SHAPE theScreen = DefaultScreen(theDisplay); @@ -632,9 +632,9 @@ InitScreen(DisplayName) theRoot = RootWindow(theDisplay, theScreen); XGetGeometry(theDisplay, theRoot, &theTempRoot, - &WindowPointX, &WindowPointY, - &WindowWidth, &WindowHeight, - &BorderWidth, &theDepth); + &WindowPointX, &WindowPointY, + &WindowWidth, &WindowHeight, + &BorderWidth, &theDepth); SetupColors(); MakeMouseCursor(); @@ -644,36 +644,36 @@ InitScreen(DisplayName) int i; for (i=0; i<5; i++) { - theTarget = Window_With_Name(theDisplay, theRoot, TargetName); - if (theTarget != None) break; + theTarget = Window_With_Name(theDisplay, theRoot, TargetName); + if (theTarget != None) break; } if (theTarget == None) { - fprintf(stderr, "%s: No window with name '%s' exists.\n", - ProgramName, TargetName); - exit(1); + fprintf(stderr, "%s: No window with name '%s' exists.\n", + ProgramName, TargetName); + exit(1); } } else { theTarget = Select_Window(theDisplay); if (theTarget == theRoot) { - theTarget = None; - ToWindow = False; + theTarget = None; + ToWindow = False; } } if (theTarget != None) { - Window QueryRoot, QueryParent, *QueryChildren; - unsigned int nchild; + Window QueryRoot, QueryParent, *QueryChildren; + unsigned int nchild; for (;;) { - if (XQueryTree(theDisplay, theTarget, &QueryRoot, - &QueryParent, &QueryChildren, &nchild)) { - XFree(QueryChildren); - if (QueryParent == QueryRoot) break; - theTarget = QueryParent; - } - else { - fprintf(stderr, "%s: Target Lost.\n",ProgramName); - exit(1); - } + if (XQueryTree(theDisplay, theTarget, &QueryRoot, + &QueryParent, &QueryChildren, &nchild)) { + XFree(QueryChildren); + if (QueryParent == QueryRoot) break; + theTarget = QueryParent; + } + else { + fprintf(stderr, "%s: Target Lost.\n",ProgramName); + exit(1); + } } } } @@ -683,16 +683,16 @@ InitScreen(DisplayName) theWindowAttributes.override_redirect = True; if (!ToWindow) XChangeWindowAttributes(theDisplay, theRoot, CWCursor, - &theWindowAttributes); + &theWindowAttributes); - theWindowMask = CWBackPixel | - CWCursor | + theWindowMask = CWBackPixel | + CWCursor | CWOverrideRedirect; theWindow = XCreateWindow(theDisplay, theRoot, 0, 0, - BITMAP_WIDTH, BITMAP_HEIGHT, - 0, theDepth, InputOutput, CopyFromParent, - theWindowMask, &theWindowAttributes); + BITMAP_WIDTH, BITMAP_HEIGHT, + 0, theDepth, InputOutput, CopyFromParent, + theWindowMask, &theWindowAttributes); if (WindowName == NULL) WindowName = ProgramName; XStoreName(theDisplay, theWindow, WindowName); @@ -700,25 +700,25 @@ InitScreen(DisplayName) InitBitmapAndGCs(); XSelectInput(theDisplay, theWindow, - ExposureMask|VisibilityChangeMask|KeyPressMask); + ExposureMask|VisibilityChangeMask|KeyPressMask); XFlush(theDisplay); } /* - * SIGINT シグナル処理 + * SIGINT シグナル処理 */ void RestoreCursor() { - XSetWindowAttributes theWindowAttributes; + XSetWindowAttributes theWindowAttributes; BitmapGCData *BitmapGCDataTablePtr; theWindowAttributes.cursor = None; XChangeWindowAttributes(theDisplay, theRoot, CWCursor, - &theWindowAttributes); + &theWindowAttributes); for (BitmapGCDataTablePtr = BitmapGCDataTable; BitmapGCDataTablePtr->GCCreatePtr != NULL; BitmapGCDataTablePtr++) { @@ -733,10 +733,10 @@ RestoreCursor() /* - * インターバル + * インターバル * - * この関数を呼ぶと、ある一定の時間返ってこなくなる。猫 - * の動作タイミング調整に利用すること。 + * この関数を呼ぶと、ある一定の時間返ってこなくなる。猫 + * の動作タイミング調整に利用すること。 */ void @@ -749,31 +749,31 @@ Interval() /* - * ティックカウント処理 + * ティックカウント処理 */ void TickCount() { if (++NekoTickCount >= MAX_TICK) { - NekoTickCount = 0; + NekoTickCount = 0; } if (NekoTickCount % 2 == 0) { - if (NekoStateCount < MAX_TICK) { - NekoStateCount++; - } + if (NekoStateCount < MAX_TICK) { + NekoStateCount++; + } } } /* - * 猫状態設定 + * 猫状態設定 */ void SetNekoState(SetValue) - int SetValue; + int SetValue; { NekoTickCount = 0; NekoStateCount = 0; @@ -783,39 +783,39 @@ SetNekoState(SetValue) /* - * 猫描画処理 + * 猫描画処理 */ void DrawNeko(x, y, DrawAnime) - int x; - int y; - Animation DrawAnime; + int x; + int y; + Animation DrawAnime; { /*@@@@@@*/ - register GC DrawGC = *(DrawAnime.TickGCPtr); - register Pixmap DrawMask = *(DrawAnime.TickMaskPtr); + register GC DrawGC = *(DrawAnime.TickGCPtr); + register Pixmap DrawMask = *(DrawAnime.TickMaskPtr); if ((x != NekoLastX) || (y != NekoLastY) - || (DrawGC != NekoLastGC)) { - XWindowChanges theChanges; + || (DrawGC != NekoLastGC)) { + XWindowChanges theChanges; theChanges.x = x; theChanges.y = y; XConfigureWindow(theDisplay, theWindow, CWX | CWY, &theChanges); #ifdef SHAPE if (NoShape == False) { - XShapeCombineMask(theDisplay, theWindow, ShapeBounding, - 0, 0, DrawMask, ShapeSet); + XShapeCombineMask(theDisplay, theWindow, ShapeBounding, + 0, 0, DrawMask, ShapeSet); } #endif SHAPE if (DontMapped) { - XMapWindow(theDisplay, theWindow); - DontMapped = 0; + XMapWindow(theDisplay, theWindow); + DontMapped = 0; } XFillRectangle(theDisplay, theWindow, DrawGC, - 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT); + 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT); } XFlush(theDisplay); @@ -828,21 +828,21 @@ DrawNeko(x, y, DrawAnime) /* - * 猫再描画処理 + * 猫再描画処理 */ void RedrawNeko() { XFillRectangle(theDisplay, theWindow, NekoLastGC, - 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT); + 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT); XFlush(theDisplay); } /* - * 猫移動方法決定 + * 猫移動方法決定 * * This sets the direction that the neko is moving. * @@ -851,80 +851,80 @@ RedrawNeko() void NekoDirection() { - int NewState; - double LargeX, LargeY; - double Length; - double SinTheta; + int NewState; + double LargeX, LargeY; + double Length; + double SinTheta; if (NekoMoveDx == 0 && NekoMoveDy == 0) { - NewState = NEKO_STOP; + NewState = NEKO_STOP; } else { - LargeX = (double)NekoMoveDx; - LargeY = (double)(-NekoMoveDy); - Length = sqrt(LargeX * LargeX + LargeY * LargeY); - SinTheta = LargeY / Length; - - if (NekoMoveDx > 0) { - if (SinTheta > SinPiPer8Times3) { - NewState = NEKO_U_MOVE; - } else if ((SinTheta <= SinPiPer8Times3) - && (SinTheta > SinPiPer8)) { - NewState = NEKO_UR_MOVE; - } else if ((SinTheta <= SinPiPer8) - && (SinTheta > -(SinPiPer8))) { - NewState = NEKO_R_MOVE; - } else if ((SinTheta <= -(SinPiPer8)) - && (SinTheta > -(SinPiPer8Times3))) { - NewState = NEKO_DR_MOVE; - } else { - NewState = NEKO_D_MOVE; - } - } else { - if (SinTheta > SinPiPer8Times3) { - NewState = NEKO_U_MOVE; - } else if ((SinTheta <= SinPiPer8Times3) - && (SinTheta > SinPiPer8)) { - NewState = NEKO_UL_MOVE; - } else if ((SinTheta <= SinPiPer8) - && (SinTheta > -(SinPiPer8))) { - NewState = NEKO_L_MOVE; - } else if ((SinTheta <= -(SinPiPer8)) - && (SinTheta > -(SinPiPer8Times3))) { - NewState = NEKO_DL_MOVE; - } else { - NewState = NEKO_D_MOVE; - } - } + LargeX = (double)NekoMoveDx; + LargeY = (double)(-NekoMoveDy); + Length = sqrt(LargeX * LargeX + LargeY * LargeY); + SinTheta = LargeY / Length; + + if (NekoMoveDx > 0) { + if (SinTheta > SinPiPer8Times3) { + NewState = NEKO_U_MOVE; + } else if ((SinTheta <= SinPiPer8Times3) + && (SinTheta > SinPiPer8)) { + NewState = NEKO_UR_MOVE; + } else if ((SinTheta <= SinPiPer8) + && (SinTheta > -(SinPiPer8))) { + NewState = NEKO_R_MOVE; + } else if ((SinTheta <= -(SinPiPer8)) + && (SinTheta > -(SinPiPer8Times3))) { + NewState = NEKO_DR_MOVE; + } else { + NewState = NEKO_D_MOVE; + } + } else { + if (SinTheta > SinPiPer8Times3) { + NewState = NEKO_U_MOVE; + } else if ((SinTheta <= SinPiPer8Times3) + && (SinTheta > SinPiPer8)) { + NewState = NEKO_UL_MOVE; + } else if ((SinTheta <= SinPiPer8) + && (SinTheta > -(SinPiPer8))) { + NewState = NEKO_L_MOVE; + } else if ((SinTheta <= -(SinPiPer8)) + && (SinTheta > -(SinPiPer8Times3))) { + NewState = NEKO_DL_MOVE; + } else { + NewState = NEKO_D_MOVE; + } + } } if (NekoState != NewState) { - SetNekoState(NewState); + SetNekoState(NewState); } } /* - * 猫壁ぶつかり判定 + * 猫壁ぶつかり判定 */ Bool IsWindowOver() { - Bool ReturnValue = False; + Bool ReturnValue = False; if (NekoY <= 0) { - NekoY = 0; - ReturnValue = True; + NekoY = 0; + ReturnValue = True; } else if (NekoY >= WindowHeight - BITMAP_HEIGHT) { - NekoY = WindowHeight - BITMAP_HEIGHT; - ReturnValue = True; + NekoY = WindowHeight - BITMAP_HEIGHT; + ReturnValue = True; } if (NekoX <= 0) { - NekoX = 0; - ReturnValue = True; + NekoX = 0; + ReturnValue = True; } else if (NekoX >= WindowWidth - BITMAP_WIDTH) { - NekoX = WindowWidth - BITMAP_WIDTH; - ReturnValue = True; + NekoX = WindowWidth - BITMAP_WIDTH; + ReturnValue = True; } return(ReturnValue); @@ -932,58 +932,58 @@ IsWindowOver() /* - * 猫移動状況判定 + * 猫移動状況判定 */ Bool IsNekoDontMove() { if (NekoX == NekoLastX && NekoY == NekoLastY) { - return(True); + return(True); } else { - return(False); + return(False); } } /* - * 猫移動開始判定 + * 猫移動開始判定 */ Bool IsNekoMoveStart() { if ((PrevMouseX >= MouseX - IdleSpace - && PrevMouseX <= MouseX + IdleSpace) && - (PrevMouseY >= MouseY - IdleSpace - && PrevMouseY <= MouseY + IdleSpace) && - (PrevTarget == theTarget)) { - return(False); + && PrevMouseX <= MouseX + IdleSpace) && + (PrevMouseY >= MouseY - IdleSpace + && PrevMouseY <= MouseY + IdleSpace) && + (PrevTarget == theTarget)) { + return(False); } else { - return(True); + return(True); } } /* - * 猫移動 dx, dy 計算 + * 猫移動 dx, dy 計算 */ void CalcDxDy() { - Window QueryRoot, QueryChild; - int AbsoluteX, AbsoluteY; - int RelativeX, RelativeY; - unsigned int ModKeyMask; - double LargeX, LargeY; - double DoubleLength, Length; + Window QueryRoot, QueryChild; + int AbsoluteX, AbsoluteY; + int RelativeX, RelativeY; + unsigned int ModKeyMask; + double LargeX, LargeY; + double DoubleLength, Length; XQueryPointer(theDisplay, theWindow, - &QueryRoot, &QueryChild, - &AbsoluteX, &AbsoluteY, - &RelativeX, &RelativeY, - &ModKeyMask); + &QueryRoot, &QueryChild, + &AbsoluteX, &AbsoluteY, + &RelativeX, &RelativeY, + &ModKeyMask); PrevMouseX = MouseX; PrevMouseY = MouseY; @@ -993,74 +993,74 @@ CalcDxDy() MouseY = AbsoluteY+YOffset; if (ToFocus) { - int revert; + int revert; XGetInputFocus(theDisplay, &theTarget, &revert); if (theTarget != theRoot - && theTarget != PointerRoot && theTarget != None) { - Window QueryParent, *QueryChildren; - unsigned int nchild; - - for (;;) { - if (XQueryTree(theDisplay, theTarget, &QueryRoot, - &QueryParent, &QueryChildren, &nchild)) { - XFree(QueryChildren); - if (QueryParent == QueryRoot) break; - theTarget = QueryParent; - } - else { - theTarget = None; - break; - } - } + && theTarget != PointerRoot && theTarget != None) { + Window QueryParent, *QueryChildren; + unsigned int nchild; + + for (;;) { + if (XQueryTree(theDisplay, theTarget, &QueryRoot, + &QueryParent, &QueryChildren, &nchild)) { + XFree(QueryChildren); + if (QueryParent == QueryRoot) break; + theTarget = QueryParent; + } + else { + theTarget = None; + break; + } + } } else { - theTarget = None; + theTarget = None; } } if ((ToWindow || ToFocus) && theTarget != None) { - int status; - XWindowAttributes theTargetAttributes; + int status; + XWindowAttributes theTargetAttributes; status = - XGetWindowAttributes(theDisplay, theTarget, &theTargetAttributes); + XGetWindowAttributes(theDisplay, theTarget, &theTargetAttributes); if (ToWindow && status == 0) { - fprintf(stderr, "%s: '%s', Target Lost.\n",ProgramName, WindowName); - RestoreCursor(); + fprintf(stderr, "%s: '%s', Target Lost.\n",ProgramName, WindowName); + RestoreCursor(); } if (theTargetAttributes.x+theTargetAttributes.width > 0 - && theTargetAttributes.x < (int)WindowWidth - && theTargetAttributes.y+theTargetAttributes.height > 0 - && theTargetAttributes.y < (int)WindowHeight - && theTargetAttributes.map_state == IsViewable) { - if (ToFocus) { - if (MouseX < theTargetAttributes.x+BITMAP_WIDTH/2) - LargeX = (double)(theTargetAttributes.x + XOffset - NekoX); - else if (MouseX > theTargetAttributes.x+theTargetAttributes.width - -BITMAP_WIDTH/2) - LargeX = (double)(theTargetAttributes.x + theTargetAttributes.width - + XOffset - NekoX - BITMAP_WIDTH); - else - LargeX = (double)(MouseX - NekoX - BITMAP_WIDTH / 2); - - LargeY = (double)(theTargetAttributes.y - + YOffset - NekoY - BITMAP_HEIGHT); - } - else { - MouseX = theTargetAttributes.x - + theTargetAttributes.width / 2 + XOffset; - MouseY = theTargetAttributes.y + YOffset; - LargeX = (double)(MouseX - NekoX - BITMAP_WIDTH / 2); - LargeY = (double)(MouseY - NekoY - BITMAP_HEIGHT); - } + && theTargetAttributes.x < (int)WindowWidth + && theTargetAttributes.y+theTargetAttributes.height > 0 + && theTargetAttributes.y < (int)WindowHeight + && theTargetAttributes.map_state == IsViewable) { + if (ToFocus) { + if (MouseX < theTargetAttributes.x+BITMAP_WIDTH/2) + LargeX = (double)(theTargetAttributes.x + XOffset - NekoX); + else if (MouseX > theTargetAttributes.x+theTargetAttributes.width + -BITMAP_WIDTH/2) + LargeX = (double)(theTargetAttributes.x + theTargetAttributes.width + + XOffset - NekoX - BITMAP_WIDTH); + else + LargeX = (double)(MouseX - NekoX - BITMAP_WIDTH / 2); + + LargeY = (double)(theTargetAttributes.y + + YOffset - NekoY - BITMAP_HEIGHT); + } + else { + MouseX = theTargetAttributes.x + + theTargetAttributes.width / 2 + XOffset; + MouseY = theTargetAttributes.y + YOffset; + LargeX = (double)(MouseX - NekoX - BITMAP_WIDTH / 2); + LargeY = (double)(MouseY - NekoY - BITMAP_HEIGHT); + } } else { - LargeX = (double)(MouseX - NekoX - BITMAP_WIDTH / 2); - LargeY = (double)(MouseY - NekoY - BITMAP_HEIGHT); + LargeX = (double)(MouseX - NekoX - BITMAP_WIDTH / 2); + LargeY = (double)(MouseY - NekoY - BITMAP_HEIGHT); } } else { @@ -1071,22 +1071,22 @@ CalcDxDy() DoubleLength = LargeX * LargeX + LargeY * LargeY; if (DoubleLength != (double)0) { - Length = sqrt(DoubleLength); - if (Length <= NekoSpeed) { - NekoMoveDx = (int)LargeX; - NekoMoveDy = (int)LargeY; - } else { - NekoMoveDx = (int)((NekoSpeed * LargeX) / Length); - NekoMoveDy = (int)((NekoSpeed * LargeY) / Length); - } + Length = sqrt(DoubleLength); + if (Length <= NekoSpeed) { + NekoMoveDx = (int)LargeX; + NekoMoveDy = (int)LargeY; + } else { + NekoMoveDx = (int)((NekoSpeed * LargeX) / Length); + NekoMoveDy = (int)((NekoSpeed * LargeY) / Length); + } } else { - NekoMoveDx = NekoMoveDy = 0; + NekoMoveDx = NekoMoveDy = 0; } } /* - * 動作解析猫描画処理 + * 動作解析猫描画処理 */ void @@ -1095,81 +1095,81 @@ NekoThinkDraw() CalcDxDy(); if (NekoState != NEKO_SLEEP) { - DrawNeko(NekoX, NekoY, - AnimationPattern[NekoState][NekoTickCount & 0x1]); + DrawNeko(NekoX, NekoY, + AnimationPattern[NekoState][NekoTickCount & 0x1]); } else { - DrawNeko(NekoX, NekoY, - AnimationPattern[NekoState][(NekoTickCount >> 2) & 0x1]); + DrawNeko(NekoX, NekoY, + AnimationPattern[NekoState][(NekoTickCount >> 2) & 0x1]); } TickCount(); switch (NekoState) { case NEKO_STOP: - if (IsNekoMoveStart()) { - SetNekoState(NEKO_AWAKE); - break; - } - if (NekoStateCount < NEKO_STOP_TIME) { - break; - } - if (NekoMoveDx < 0 && NekoX <= 0) { - SetNekoState(NEKO_L_TOGI); - } else if (NekoMoveDx > 0 && NekoX >= WindowWidth - BITMAP_WIDTH) { - SetNekoState(NEKO_R_TOGI); - } else if ((NekoMoveDy < 0 && NekoY <= 0) - || (ToFocus && theTarget != None && NekoY > MouseY)){ - SetNekoState(NEKO_U_TOGI); - } else if ((NekoMoveDy > 0 && NekoY >= WindowHeight - BITMAP_HEIGHT) - || (ToFocus && theTarget != None - && NekoY < MouseY - BITMAP_HEIGHT)){ - SetNekoState(NEKO_D_TOGI); - } else { - SetNekoState(NEKO_JARE); - } - break; + if (IsNekoMoveStart()) { + SetNekoState(NEKO_AWAKE); + break; + } + if (NekoStateCount < NEKO_STOP_TIME) { + break; + } + if (NekoMoveDx < 0 && NekoX <= 0) { + SetNekoState(NEKO_L_TOGI); + } else if (NekoMoveDx > 0 && NekoX >= WindowWidth - BITMAP_WIDTH) { + SetNekoState(NEKO_R_TOGI); + } else if ((NekoMoveDy < 0 && NekoY <= 0) + || (ToFocus && theTarget != None && NekoY > MouseY)){ + SetNekoState(NEKO_U_TOGI); + } else if ((NekoMoveDy > 0 && NekoY >= WindowHeight - BITMAP_HEIGHT) + || (ToFocus && theTarget != None + && NekoY < MouseY - BITMAP_HEIGHT)){ + SetNekoState(NEKO_D_TOGI); + } else { + SetNekoState(NEKO_JARE); + } + break; case NEKO_JARE: - if (IsNekoMoveStart()) { - SetNekoState(NEKO_AWAKE); - break; - } - if (NekoStateCount < NEKO_JARE_TIME) { - break; - } - SetNekoState(NEKO_KAKI); - break; + if (IsNekoMoveStart()) { + SetNekoState(NEKO_AWAKE); + break; + } + if (NekoStateCount < NEKO_JARE_TIME) { + break; + } + SetNekoState(NEKO_KAKI); + break; case NEKO_KAKI: - if (IsNekoMoveStart()) { - SetNekoState(NEKO_AWAKE); - break; - } - if (NekoStateCount < NEKO_KAKI_TIME) { - break; - } - SetNekoState(NEKO_AKUBI); - break; + if (IsNekoMoveStart()) { + SetNekoState(NEKO_AWAKE); + break; + } + if (NekoStateCount < NEKO_KAKI_TIME) { + break; + } + SetNekoState(NEKO_AKUBI); + break; case NEKO_AKUBI: - if (IsNekoMoveStart()) { - SetNekoState(NEKO_AWAKE); - break; - } - if (NekoStateCount < NEKO_AKUBI_TIME) { - break; - } - SetNekoState(NEKO_SLEEP); - break; + if (IsNekoMoveStart()) { + SetNekoState(NEKO_AWAKE); + break; + } + if (NekoStateCount < NEKO_AKUBI_TIME) { + break; + } + SetNekoState(NEKO_SLEEP); + break; case NEKO_SLEEP: - if (IsNekoMoveStart()) { - SetNekoState(NEKO_AWAKE); - break; - } - break; + if (IsNekoMoveStart()) { + SetNekoState(NEKO_AWAKE); + break; + } + break; case NEKO_AWAKE: - if (NekoStateCount < NEKO_AWAKE_TIME) { - break; - } - NekoDirection(); /* 猫が動く向きを求める */ - break; + if (NekoStateCount < NEKO_AWAKE_TIME) { + break; + } + NekoDirection(); /* 猫が動く向きを求める */ + break; case NEKO_U_MOVE: case NEKO_D_MOVE: case NEKO_L_MOVE: @@ -1178,32 +1178,32 @@ NekoThinkDraw() case NEKO_UR_MOVE: case NEKO_DL_MOVE: case NEKO_DR_MOVE: - NekoX += NekoMoveDx; - NekoY += NekoMoveDy; - NekoDirection(); - if (IsWindowOver()) { - if (IsNekoDontMove()) { - SetNekoState(NEKO_STOP); - } - } - break; + NekoX += NekoMoveDx; + NekoY += NekoMoveDy; + NekoDirection(); + if (IsWindowOver()) { + if (IsNekoDontMove()) { + SetNekoState(NEKO_STOP); + } + } + break; case NEKO_U_TOGI: case NEKO_D_TOGI: case NEKO_L_TOGI: case NEKO_R_TOGI: - if (IsNekoMoveStart()) { - SetNekoState(NEKO_AWAKE); - break; - } - if (NekoStateCount < NEKO_TOGI_TIME) { - break; - } - SetNekoState(NEKO_KAKI); - break; + if (IsNekoMoveStart()) { + SetNekoState(NEKO_AWAKE); + break; + } + if (NekoStateCount < NEKO_TOGI_TIME) { + break; + } + SetNekoState(NEKO_KAKI); + break; default: - /* Internal Error */ - SetNekoState(NEKO_STOP); - break; + /* Internal Error */ + SetNekoState(NEKO_STOP); + break; } Interval(); @@ -1211,32 +1211,32 @@ NekoThinkDraw() /* - * キーイベント処理 + * キーイベント処理 */ Bool ProcessKeyPress(theKeyEvent) - XKeyEvent *theKeyEvent; + XKeyEvent *theKeyEvent; { - int Length; - int theKeyBufferMaxLen = AVAIL_KEYBUF; - char theKeyBuffer[AVAIL_KEYBUF + 1]; - KeySym theKeySym; - XComposeStatus theComposeStatus; - Bool ReturnState; + int Length; + int theKeyBufferMaxLen = AVAIL_KEYBUF; + char theKeyBuffer[AVAIL_KEYBUF + 1]; + KeySym theKeySym; + XComposeStatus theComposeStatus; + Bool ReturnState; ReturnState = True; Length = XLookupString(theKeyEvent, - theKeyBuffer, theKeyBufferMaxLen, - &theKeySym, &theComposeStatus); + theKeyBuffer, theKeyBufferMaxLen, + &theKeySym, &theComposeStatus); if (Length > 0) { switch (theKeyBuffer[0]) { case 'q': case 'Q': if (theKeyEvent->state & Mod1Mask) { /* META (Alt) キー */ - ReturnState = False; + ReturnState = False; } break; default: @@ -1249,38 +1249,38 @@ ProcessKeyPress(theKeyEvent) /* - * イベント処理 + * イベント処理 */ Bool ProcessEvent() { - XEvent theEvent; - Bool ContinueState = True; + XEvent theEvent; + Bool ContinueState = True; while (XPending(theDisplay)) { XNextEvent(theDisplay,&theEvent); - switch (theEvent.type) { - case Expose: - if (theEvent.xexpose.count == 0) { - RedrawNeko(); - } - break; - case KeyPress: - ContinueState = ProcessKeyPress(&theEvent); - if (!ContinueState) { - return(ContinueState); - } - break; - case VisibilityNotify: - if (RaiseWindowDelay==0) { - XRaiseWindow(theDisplay,theWindow); - RaiseWindowDelay=DEFAULT_RAISE_WAIT; - } - default: - /* Unknown Event */ - break; - } + switch (theEvent.type) { + case Expose: + if (theEvent.xexpose.count == 0) { + RedrawNeko(); + } + break; + case KeyPress: + ContinueState = ProcessKeyPress(&theEvent); + if (!ContinueState) { + return(ContinueState); + } + break; + case VisibilityNotify: + if (RaiseWindowDelay==0) { + XRaiseWindow(theDisplay,theWindow); + RaiseWindowDelay=DEFAULT_RAISE_WAIT; + } + default: + /* Unknown Event */ + break; + } } return(ContinueState); @@ -1288,13 +1288,13 @@ ProcessEvent() /* - * 猫処理 + * 猫処理 */ void ProcessNeko() { - struct itimerval Value; + struct itimerval Value; /* 猫の初期化 */ @@ -1325,7 +1325,7 @@ ProcessNeko() /* - * SIGALRM シグナル処理 + * SIGALRM シグナル処理 */ static void @@ -1338,13 +1338,13 @@ NullFunction() } /* - * エラー処理 + * エラー処理 */ int NekoErrorHandler(dpy, err) - Display *dpy; - XErrorEvent *err; + Display *dpy; + XErrorEvent *err; { if (err->error_code==BadWindow && (ToWindow || ToFocus)) { } @@ -1358,23 +1358,23 @@ NekoErrorHandler(dpy, err) /* - * Usage + * Usage */ -char *message[] = { +char *message[] = { "", "Options are:", -"-display <display> : Neko appears on specified display.", -"-fg <color> : Foreground color", -"-bg <color> : Background color", +"-display <display> : Neko appears on specified display.", +"-fg <color> : Foreground color", +"-bg <color> : Background color", "-speed <dots>", "-time <microseconds>", "-idle <dots>", -"-name <name> : set window name of neko.", -"-towindow : Neko chases selected window.", -"-toname <name> : Neko chases specified window.", -"-tofocus : Neko runs on top of focus window", -"-rv : Reverse video. (effects monochrome display only)", +"-name <name> : set window name of neko.", +"-towindow : Neko chases selected window.", +"-toname <name> : Neko chases specified window.", +"-tofocus : Neko runs on top of focus window", +"-rv : Reverse video. (effects monochrome display only)", "-position <geometry> : adjust position relative to mouse pointer.", "-debug : puts you in synchronous mode.", "-patchlevel : print out your current patchlevel.", @@ -1383,7 +1383,7 @@ NULL }; void Usage() { - char **mptr; + char **mptr; int loop; mptr = message; @@ -1398,16 +1398,16 @@ Usage() /* - * オプションの理解 + * オプションの理解 */ Bool GetArguments(argc, argv, theDisplayName) - int argc; - char *argv[]; - char *theDisplayName; + int argc; + char *argv[]; + char *theDisplayName; { - int ArgCounter; + int ArgCounter; int result,foo,bar; extern int XOffset,YOffset; int loop,found=0; @@ -1423,46 +1423,46 @@ GetArguments(argc, argv, theDisplayName) if (strcmp(argv[ArgCounter], "-display") == 0) { ArgCounter++; if (ArgCounter < argc) { - strcpy(theDisplayName, argv[ArgCounter]); + strcpy(theDisplayName, argv[ArgCounter]); } else { - fprintf(stderr, "%s: -display option error.\n", ProgramName); - exit(1); + fprintf(stderr, "%s: -display option error.\n", ProgramName); + exit(1); } } else if (strcmp(argv[ArgCounter], "-speed") == 0) { ArgCounter++; if (ArgCounter < argc) { - NekoSpeed = atof(argv[ArgCounter]); + NekoSpeed = atof(argv[ArgCounter]); } else { - fprintf(stderr, "%s: -speed option error.\n", ProgramName); - exit(1); + fprintf(stderr, "%s: -speed option error.\n", ProgramName); + exit(1); } } else if (strcmp(argv[ArgCounter], "-time") == 0) { ArgCounter++; if (ArgCounter < argc) { - IntervalTime = atol(argv[ArgCounter]); + IntervalTime = atol(argv[ArgCounter]); } else { - fprintf(stderr, "%s: -time option error.\n", ProgramName); - exit(1); + fprintf(stderr, "%s: -time option error.\n", ProgramName); + exit(1); } } else if (strcmp(argv[ArgCounter], "-idle") == 0) { ArgCounter++; if (ArgCounter < argc) { - IdleSpace = atol(argv[ArgCounter]); + IdleSpace = atol(argv[ArgCounter]); } else { - fprintf(stderr, "%s: -idle option error.\n", ProgramName); - exit(1); + fprintf(stderr, "%s: -idle option error.\n", ProgramName); + exit(1); } } else if (strcmp(argv[ArgCounter], "-name") == 0) { ArgCounter++; if (ArgCounter < argc) { - WindowName = argv[ArgCounter]; + WindowName = argv[ArgCounter]; } else { - fprintf(stderr, "%s: -name option error.\n", ProgramName); - exit(1); + fprintf(stderr, "%s: -name option error.\n", ProgramName); + exit(1); } } else if (strcmp(argv[ArgCounter], "-towindow") == 0) { @@ -1472,12 +1472,12 @@ GetArguments(argc, argv, theDisplayName) else if (strcmp(argv[ArgCounter], "-toname") == 0) { ArgCounter++; if (ArgCounter < argc) { - TargetName = argv[ArgCounter]; - ToWindow = True; - ToFocus = False; + TargetName = argv[ArgCounter]; + ToWindow = True; + ToFocus = False; } else { - fprintf(stderr, "%s: -toname option error.\n", ProgramName); - exit(1); + fprintf(stderr, "%s: -toname option error.\n", ProgramName); + exit(1); } } else if (strcmp(argv[ArgCounter], "-tofocus") == 0) { @@ -1485,15 +1485,15 @@ GetArguments(argc, argv, theDisplayName) ToWindow = False; } else if ((strcmp(argv[ArgCounter], "-fg") == 0) || - (strcmp(argv[ArgCounter], "-foreground") == 0)) { + (strcmp(argv[ArgCounter], "-foreground") == 0)) { ArgCounter++; Foreground = argv[ArgCounter]; - } + } else if ((strcmp(argv[ArgCounter], "-bg") == 0) || - (strcmp(argv[ArgCounter], "-background") == 0)) { + (strcmp(argv[ArgCounter], "-background") == 0)) { ArgCounter++; Background = argv[ArgCounter]; - } + } else if (strcmp(argv[ArgCounter], "-rv") == 0) { ReverseVideo = True; } @@ -1513,17 +1513,17 @@ GetArguments(argc, argv, theDisplayName) else { char *av = argv[ArgCounter] + 1; if (strcmp(av, "bsd") == 0) - av = "bsd_daemon"; + av = "bsd_daemon"; for (loop=0;loop<BITMAPTYPES;loop++) { - if (strcmp(av,AnimalDefaultsDataTable[loop].name)==0) - {NekoMoyou = loop;found=1;} + if (strcmp(av,AnimalDefaultsDataTable[loop].name)==0) + {NekoMoyou = loop;found=1;} } if (!found) { - fprintf(stderr, - "%s: Unknown option \"%s\".\n", ProgramName, - argv[ArgCounter]); - Usage(); - exit(1); + fprintf(stderr, + "%s: Unknown option \"%s\".\n", ProgramName, + argv[ArgCounter]); + Usage(); + exit(1); } } } @@ -1535,15 +1535,15 @@ GetArguments(argc, argv, theDisplayName) /* - * メイン関数 + * メイン関数 */ int main(argc, argv) - int argc; - char *argv[]; + int argc; + char *argv[]; { - char theDisplayName[MAXDISPLAYNAME]; + char theDisplayName[MAXDISPLAYNAME]; ProgramName = argv[0]; diff --git a/oneko.h b/oneko.h index 0b0566a..2362397 100644 --- a/oneko.h +++ b/oneko.h @@ -1,11 +1,11 @@ /* - * oneko - X11 猫 + * oneko - X11 猫 * - * $Header: /home/sun/unix/kato/xsam/oneko/oneko.h,v 1.4 90/10/18 16:52:57 kato Exp Locker: kato $ + * $Header: /home/sun/unix/kato/xsam/oneko/oneko.h,v 1.4 90/10/18 16:52:57 kato Exp Locker: kato $ */ /* - * インクルードファイル + * インクルードファイル */ #include <X11/Xlib.h> @@ -22,13 +22,13 @@ /* - * カーソルビットマップファイルの読み込み + * カーソルビットマップファイルの読み込み */ #include "cursors/cursor.include" /* - * 普通の猫用ビットマップファイルの読み込み + * 普通の猫用ビットマップファイルの読み込み * These include files in the directories noted. * These are the bitmaps. */ @@ -49,60 +49,60 @@ #include "bitmasks/tomoyo/tomoyo.mask.include" /* - * 定数定義 + * 定数定義 */ -#define BITMAP_WIDTH 32 /* 1キャラクタの幅 (ピクセル) */ -#define BITMAP_HEIGHT 32 /* 1キャラクタの高さ (ピクセル) */ +#define BITMAP_WIDTH 32 /* 1キャラクタの幅 (ピクセル) */ +#define BITMAP_HEIGHT 32 /* 1キャラクタの高さ (ピクセル) */ -#define AVAIL_KEYBUF 255 -#define MAX_TICK 9999 /* Odd Only! */ +#define AVAIL_KEYBUF 255 +#define MAX_TICK 9999 /* Odd Only! */ -#define DEFAULT_FOREGROUND "black" /* フォアグラウンドカラー */ -#define DEFAULT_BACKGROUND "white" /* バックグラウンドカラー */ +#define DEFAULT_FOREGROUND "black" /* フォアグラウンドカラー */ +#define DEFAULT_BACKGROUND "white" /* バックグラウンドカラー */ /* - * 猫の状態定数 + * 猫の状態定数 */ -#define NEKO_STOP 0 /* 立ち止まった */ -#define NEKO_JARE 1 /* 顔を洗っている */ -#define NEKO_KAKI 2 /* 頭を掻いている */ -#define NEKO_AKUBI 3 /* あくびをしている */ -#define NEKO_SLEEP 4 /* 寝てしまった */ -#define NEKO_AWAKE 5 /* 目が覚めた */ -#define NEKO_U_MOVE 6 /* 上に移動中 */ -#define NEKO_D_MOVE 7 /* 下に移動中 */ -#define NEKO_L_MOVE 8 /* 左に移動中 */ -#define NEKO_R_MOVE 9 /* 右に移動中 */ -#define NEKO_UL_MOVE 10 /* 左上に移動中 */ -#define NEKO_UR_MOVE 11 /* 右上に移動中 */ -#define NEKO_DL_MOVE 12 /* 左下に移動中 */ -#define NEKO_DR_MOVE 13 /* 右下に移動中 */ -#define NEKO_U_TOGI 14 /* 上の壁を引っ掻いている */ -#define NEKO_D_TOGI 15 /* 下の壁を引っ掻いている */ -#define NEKO_L_TOGI 16 /* 左の壁を引っ掻いている */ -#define NEKO_R_TOGI 17 /* 右の壁を引っ掻いている */ +#define NEKO_STOP 0 /* 立ち止まった */ +#define NEKO_JARE 1 /* 顔を洗っている */ +#define NEKO_KAKI 2 /* 頭を掻いている */ +#define NEKO_AKUBI 3 /* あくびをしている */ +#define NEKO_SLEEP 4 /* 寝てしまった */ +#define NEKO_AWAKE 5 /* 目が覚めた */ +#define NEKO_U_MOVE 6 /* 上に移動中 */ +#define NEKO_D_MOVE 7 /* 下に移動中 */ +#define NEKO_L_MOVE 8 /* 左に移動中 */ +#define NEKO_R_MOVE 9 /* 右に移動中 */ +#define NEKO_UL_MOVE 10 /* 左上に移動中 */ +#define NEKO_UR_MOVE 11 /* 右上に移動中 */ +#define NEKO_DL_MOVE 12 /* 左下に移動中 */ +#define NEKO_DR_MOVE 13 /* 右下に移動中 */ +#define NEKO_U_TOGI 14 /* 上の壁を引っ掻いている */ +#define NEKO_D_TOGI 15 /* 下の壁を引っ掻いている */ +#define NEKO_L_TOGI 16 /* 左の壁を引っ掻いている */ +#define NEKO_R_TOGI 17 /* 右の壁を引っ掻いている */ /* - * 猫のアニメーション繰り返し回数 + * 猫のアニメーション繰り返し回数 */ -#define NEKO_STOP_TIME 4 -#define NEKO_JARE_TIME 10 -#define NEKO_KAKI_TIME 4 -#define NEKO_AKUBI_TIME 6 /* もともと3だったけど長い方がいい */ -#define NEKO_AWAKE_TIME 3 -#define NEKO_TOGI_TIME 10 +#define NEKO_STOP_TIME 4 +#define NEKO_JARE_TIME 10 +#define NEKO_KAKI_TIME 4 +#define NEKO_AKUBI_TIME 6 /* もともと3だったけど長い方がいい */ +#define NEKO_AWAKE_TIME 3 +#define NEKO_TOGI_TIME 10 -#define PI_PER8 ((double)3.1415926535/(double)8) +#define PI_PER8 ((double)3.1415926535/(double)8) -#define MAXDISPLAYNAME (64 + 5) /* ディスプレイ名の長さ */ +#define MAXDISPLAYNAME (64 + 5) /* ディスプレイ名の長さ */ -#define NOTDEFINED (-1) +#define NOTDEFINED (-1) /* - * マクロ定義 + * マクロ定義 */ #define IsTrue(str) (strcmp((str), "true") == 0) |