JWM Source Documentation
cursor.c
Go to the documentation of this file.
1 
10 #include "jwm.h"
11 #include "cursor.h"
12 #include "main.h"
13 
15 typedef enum {
28 } CursorType;
29 
33 static const unsigned int cursor_shapes[CURSOR_COUNT] = {
34  XC_left_ptr,
35  XC_fleur,
36  XC_top_side,
37  XC_bottom_side,
38  XC_right_side,
39  XC_left_side,
40  XC_top_right_corner,
41  XC_top_left_corner,
42  XC_bottom_right_corner,
43  XC_bottom_left_corner,
44  XC_tcross
45 };
46 
47 static Cursor cursors[CURSOR_COUNT];
48 
49 static Cursor GetResizeCursor(BorderActionType action);
50 static Cursor CreateCursor(unsigned int shape);
51 
52 static int mousex;
53 static int mousey;
54 static Window mousew;
55 
57 void StartupCursors(void)
58 {
59 
60  Window win1;
61  int winx, winy;
62  unsigned int mask;
63  int x;
64 
65  for(x = 0; x < CURSOR_COUNT; x++) {
67  }
68 
70  &mousex, &mousey, &winx, &winy, &mask);
71 
72 }
73 
75 Cursor CreateCursor(unsigned int shape)
76 {
77  return JXCreateFontCursor(display, shape);
78 }
79 
81 void ShutdownCursors(void)
82 {
83  int x;
84  for(x = 0; x < CURSOR_COUNT; x++) {
86  }
87 }
88 
91 {
92  switch(action & 0x0F) {
93  case BA_RESIZE:
94  return GetResizeCursor(action);
95  case BA_CLOSE:
96  break;
97  case BA_MAXIMIZE:
98  break;
99  case BA_MINIMIZE:
100  break;
101  case BA_MOVE:
102  break;
103  default:
104  break;
105  }
106  return cursors[CURSOR_DEFAULT];
107 }
108 
111 {
112  if(action & BA_RESIZE_N) {
113  if(action & BA_RESIZE_E) {
114  return cursors[CURSOR_NE];
115  } else if(action & BA_RESIZE_W) {
116  return cursors[CURSOR_NW];
117  } else {
118  return cursors[CURSOR_NORTH];
119  }
120  } else if(action & BA_RESIZE_S) {
121  if(action & BA_RESIZE_E) {
122  return cursors[CURSOR_SE];
123  } else if(action & BA_RESIZE_W) {
124  return cursors[CURSOR_SW];
125  } else {
126  return cursors[CURSOR_SOUTH];
127  }
128  } else if(action & BA_RESIZE_E) {
129  return cursors[CURSOR_EAST];
130  } else if(action & BA_RESIZE_W) {
131  return cursors[CURSOR_WEST];
132  } else {
133  return cursors[CURSOR_DEFAULT];
134  }
135 }
136 
139 {
140  Cursor cur;
141  int result;
142  unsigned int mask;
143 
144  cur = GetFrameCursor(action);
145  mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
146  result = JXGrabPointer(display, rootWindow, False, mask,
147  GrabModeAsync, GrabModeAsync, None,
148  cur, CurrentTime);
149  if(JLIKELY(result == GrabSuccess)) {
150  mousew = rootWindow;
151  return 1;
152  } else {
153  return 0;
154  }
155 }
156 
159 {
160  int result;
161  unsigned int mask;
162  mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
163  result = JXGrabPointer(display, rootWindow, False, mask,
164  GrabModeAsync, GrabModeAsync, None,
165  cursors[CURSOR_MOVE], CurrentTime);
166  if(JLIKELY(result == GrabSuccess)) {
167  mousew = rootWindow;
168  return 1;
169  } else {
170  return 0;
171  }
172 }
173 
175 char GrabMouse(Window w)
176 {
177  int result;
178  unsigned int mask;
179  mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
180  result = JXGrabPointer(display, w, False, mask,
181  GrabModeAsync, GrabModeAsync, None,
182  cursors[CURSOR_DEFAULT], CurrentTime);
183  if(JLIKELY(result == GrabSuccess)) {
184  mousew = w;
185  return 1;
186  } else {
187  return 0;
188  }
189 }
190 
193 {
194  int result;
195  unsigned int mask;
196  mask = ButtonPressMask | ButtonReleaseMask;
197  result = JXGrabPointer(display, rootWindow, False, mask,
198  GrabModeAsync, GrabModeAsync, None,
199  cursors[CURSOR_CHOOSE], CurrentTime);
200  if(JLIKELY(result == GrabSuccess)) {
201  mousew = rootWindow;
202  return 1;
203  } else {
204  return 0;
205  }
206 }
207 
209 void SetDefaultCursor(Window w)
210 {
211  if(JLIKELY(w != None)) {
213  }
214 }
215 
217 void MoveMouse(Window win, int x, int y)
218 {
219  Window win1;
220  int winx, winy;
221  unsigned int mask;
222  JXWarpPointer(display, None, win, 0, 0, 0, 0, x, y);
224  &mousex, &mousey, &winx, &winy, &mask);
225 }
226 
228 void SetMousePosition(int x, int y, Window w)
229 {
230  mousex = x;
231  mousey = y;
232  mousew = w;
233 }
234 
236 void GetMousePosition(int *x, int *y, Window *w)
237 {
238  *x = mousex;
239  *y = mousey;
240  *w = mousew;
241 }
242 
244 unsigned int GetMouseMask(void)
245 {
246  Window win1;
247  int winx, winy;
248  unsigned int mask;
250  &mousex, &mousey, &winx, &winy, &mask);
251  return mask;
252 }

joewing.net / Projects / JWM