~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/X11/mousestate.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 /**
  4 tv_screen_mousestate.c:
  5 Simple description of current mouse event.
  6 **/
  7 
  8 #include <stdio.h>
  9 #include <tina/sys.h>
 10 #include <tina/sysfuncs.h>
 11 #include <tina/math.h>
 12 #include <tina/tv.h>
 13 #include <tina/tv_screen.h>
 14 
 15 void    format_mousestate(int state)
 16 {
 17     switch (state)
 18     {
 19         case LEFT_DOWN:
 20         format("LEFT_DOWN\n");
 21         break;
 22     case LEFT_DRAG:
 23         format("LEFT_DRAG\n");
 24         break;
 25     case LEFT_UP:
 26         format("LEFT_UP\n");
 27         break;
 28     case MIDDLE_DOWN:
 29         format("MIDDLE_DOWN\n");
 30         break;
 31     case MIDDLE_DRAG:
 32         format("MIDDLE_DRAG\n");
 33         break;
 34     case MIDDLE_UP:
 35         format("MIDDLE_UP\n");
 36         break;
 37     case RIGHT_DOWN:
 38         format("RIGHT_DOWN\n");
 39         break;
 40     case RIGHT_DRAG:
 41         format("RIGHT_DRAG\n");
 42         break;
 43     case RIGHT_UP:
 44         format("RIGHT_UP\n");
 45         break;
 46     case WAIT_STATE:
 47         format("WAIT_STATE\n");
 48         break;
 49     case BAD_STATE:
 50         format("BAD_STATE\n");
 51         break;
 52     default:
 53         format("STRANGE_STATE\n");
 54         break;
 55     }
 56 }
 57 
 58 int     mouse_get_state(XEvent * event, Ipos * pos)
 59 {
 60     static int mouse_state = BAD_STATE;
 61 
 62     switch (event->type)
 63     {
 64     case ButtonPress:
 65         switch (event->xbutton.button)
 66         {
 67         case Button1:
 68             mouse_state = LEFT_DOWN;
 69             break;
 70         case Button2:
 71             mouse_state = MIDDLE_DOWN;
 72             break;
 73         case Button3:
 74             mouse_state = RIGHT_DOWN;
 75             break;
 76         default:
 77             return (BAD_STATE);
 78         }
 79         break;
 80     case MotionNotify:
 81 
 82         /* Compress MotionNotify events */
 83         {
 84             Display *display = event->xmotion.display;
 85             XEvent  ahead;
 86 
 87             while (XEventsQueued(display, QueuedAfterReading) > 0 &&
 88             (XPeekEvent(display, &ahead), ahead.type == MotionNotify))
 89             {
 90                 XNextEvent(display, event);
 91             }
 92         }
 93 
 94         switch (mouse_state)
 95         {
 96 
 97         case LEFT_DOWN:
 98         case LEFT_DRAG:
 99             mouse_state = LEFT_DRAG;
100             break;
101         case MIDDLE_DOWN:
102         case MIDDLE_DRAG:
103             mouse_state = MIDDLE_DRAG;
104             break;
105         case RIGHT_DOWN:
106         case RIGHT_DRAG:
107             mouse_state = RIGHT_DRAG;
108             break;
109         default:
110             return (BAD_STATE);
111         }
112         break;
113     case ButtonRelease:
114         switch (event->xbutton.button)
115         {
116         case Button1:
117             mouse_state = LEFT_UP;
118             break;
119         case Button2:
120             mouse_state = MIDDLE_UP;
121             break;
122         case Button3:
123             mouse_state = RIGHT_UP;
124             break;
125         default:
126             return (BAD_STATE);
127         }
128         break;
129     default:
130         return (BAD_STATE);
131     }
132 
133     switch (event->type)
134     {
135     case ButtonPress:
136     case ButtonRelease:
137         pos->x = event->xbutton.x;
138         pos->y = event->xbutton.y;
139         break;
140     case MotionNotify:
141         pos->x = event->xmotion.x;
142         pos->y = event->xmotion.y;
143         break;
144     }
145 
146     return (mouse_state);
147 }
148 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.