f7b8f66fd269be12329ee6a74e64ba50d66b9600
[freeglut] / src / blackberry / fg_main_blackberry.c
1 /*
2  * fg_main_blackberry.c
3  *
4  * The BlackBerry-specific windows message processing methods.
5  *
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8  * Copied for Platform code by Evan Felix <karcaw at gmail.com>
9  * Copyright (C) 2012  Sylvain Beucler
10  * Copyright (C) 2013  Vincent Simonetti
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
25  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  */
29
30 #include <GL/freeglut.h>
31 #include "fg_internal.h"
32 #include "egl/fg_window_egl.h"
33
34 #include <slog2.h>
35 #define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__, SLOG2_FA_END))
36 #define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__, SLOG2_FA_END))
37 #include <sys/keycodes.h>
38 #include <input/screen_helpers.h>
39 #include <bps/bps.h>
40 #include <bps/event.h>
41 #include <bps/screen.h>
42 #include <bps/navigator.h>
43
44 extern void fghOnReshapeNotify(SFG_Window *window, int width, int height, GLboolean forceNotify);
45 extern void fghOnPositionNotify(SFG_Window *window, int x, int y, GLboolean forceNotify);
46 extern void fgPlatformFullScreenToggle( SFG_Window *win );
47 extern void fgPlatformPositionWindow( SFG_Window *window, int x, int y );
48 extern void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height );
49 extern void fgPlatformPushWindow( SFG_Window *window );
50 extern void fgPlatformPopWindow( SFG_Window *window );
51 extern void fgPlatformHideWindow( SFG_Window *window );
52 extern void fgPlatformIconifyWindow( SFG_Window *window );
53 extern void fgPlatformShowWindow( SFG_Window *window );
54
55 static struct touchscreen touchscreen;
56
57 unsigned int key_special(int qnxKeycode)
58 {
59     switch(qnxKeycode) {
60     case KEYCODE_F1:
61         return GLUT_KEY_F1;
62     case KEYCODE_F2:
63         return GLUT_KEY_F2;
64     case KEYCODE_F3:
65         return GLUT_KEY_F3;
66     case KEYCODE_F4:
67         return GLUT_KEY_F4;
68     case KEYCODE_F5:
69         return GLUT_KEY_F5;
70     case KEYCODE_F6:
71         return GLUT_KEY_F6;
72     case KEYCODE_F7:
73         return GLUT_KEY_F7;
74     case KEYCODE_F8:
75         return GLUT_KEY_F8;
76     case KEYCODE_F9:
77         return GLUT_KEY_F9;
78     case KEYCODE_F10:
79         return GLUT_KEY_F10;
80     case KEYCODE_F11:
81         return GLUT_KEY_F11;
82     case KEYCODE_F12:
83         return GLUT_KEY_F12;
84     case KEYCODE_PG_UP:
85         return GLUT_KEY_PAGE_UP;
86     case KEYCODE_PG_DOWN:
87         return GLUT_KEY_PAGE_DOWN;
88     case KEYCODE_HOME:
89         return GLUT_KEY_HOME;
90     case KEYCODE_END:
91         return GLUT_KEY_END;
92     case KEYCODE_INSERT:
93         return GLUT_KEY_INSERT;
94     case KEYCODE_UP:
95     //case KEYCODE_KP_UP:
96         return GLUT_KEY_UP;
97     case KEYCODE_DOWN:
98     //case KEYCODE_KP_DOWN:
99         return GLUT_KEY_DOWN;
100     case KEYCODE_LEFT:
101     //case KEYCODE_KP_LEFT:
102         return GLUT_KEY_LEFT;
103     case KEYCODE_RIGHT:
104     //case KEYCODE_KP_RIGHT:
105         return GLUT_KEY_RIGHT;
106     case KEYCODE_NUM_LOCK:
107         return GLUT_KEY_NUM_LOCK;
108     case KEYCODE_LEFT_ALT:
109         return GLUT_KEY_ALT_L;
110     case KEYCODE_RIGHT_ALT:
111         return GLUT_KEY_ALT_R;
112     case KEYCODE_LEFT_SHIFT:
113         return GLUT_KEY_SHIFT_L;
114     case KEYCODE_RIGHT_SHIFT:
115         return GLUT_KEY_SHIFT_R;
116     case KEYCODE_LEFT_CTRL:
117         return GLUT_KEY_CTRL_L;
118     case KEYCODE_RIGHT_CTRL:
119         return GLUT_KEY_CTRL_R;
120     }
121     return 0;
122 }
123
124 unsigned char key_ascii(int qnxKeycode)
125 {
126     if (qnxKeycode >= KEYCODE_PC_KEYS && qnxKeycode <= UNICODE_PRIVATE_USE_AREA_LAST) {
127         switch (qnxKeycode) {
128         case KEYCODE_BACKSPACE:
129             return 0x0008;
130         case KEYCODE_TAB:
131             return 0x0009;
132         case KEYCODE_KP_ENTER:
133         case KEYCODE_RETURN:
134             return 0x000A;
135         case KEYCODE_ESCAPE:
136             return 0x001B;
137         }
138     }
139     return qnxKeycode;
140 }
141
142 //From fg_main_x11
143 fg_time_t fgPlatformSystemTime ( void )
144 {
145 #ifdef CLOCK_MONOTONIC
146     struct timespec now;
147     clock_gettime(CLOCK_MONOTONIC, &now);
148     return now.tv_nsec/1000000 + now.tv_sec*1000;
149 #elif defined(HAVE_GETTIMEOFDAY)
150     struct timeval now;
151     gettimeofday( &now, NULL );
152     return now.tv_usec/1000 + now.tv_sec*1000;
153 #endif
154 }
155
156 /*
157  * Does the magic required to relinquish the CPU until something interesting
158  * happens.
159  */
160 void fgPlatformSleepForEvents( fg_time_t msec )
161 {
162     //XXX: Is this right? Is there a more direct way to access the context?
163     if(bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) {
164         LOGW("BPS couldn't get event");
165     }
166 }
167
168 void handle_left_mouse(int x, int y, int height, int eventType, SFG_Window* window)
169 {
170     bool handled = false;
171     /* Virtual arrows PAD */
172     /* Don't interfere with existing mouse move event */
173     if (!touchscreen.in_mmotion) {
174         struct vpad_state prev_vpad = touchscreen.vpad;
175         touchscreen.vpad.left = touchscreen.vpad.right = touchscreen.vpad.up = touchscreen.vpad.down = false;
176
177         if (eventType == SCREEN_EVENT_MTOUCH_TOUCH || eventType == SCREEN_EVENT_MTOUCH_MOVE) {
178             if ((x > 0 && x < 100) && (y > (height - 100) && y < height))
179             {
180                 touchscreen.vpad.left = true;
181             }
182             if ((x > 200 && x < 300) && (y > (height - 100) && y < height))
183             {
184                 touchscreen.vpad.right = true;
185             }
186             if ((x > 100 && x < 200) && (y > (height - 100) && y < height))
187             {
188                 touchscreen.vpad.down = true;
189             }
190             if ((x > 100 && x < 200) && (y > (height - 200) && y < (height - 100)))
191             {
192                 touchscreen.vpad.up = true;
193             }
194         }
195
196         if (eventType == SCREEN_EVENT_MTOUCH_TOUCH &&
197                 (touchscreen.vpad.left || touchscreen.vpad.right || touchscreen.vpad.down || touchscreen.vpad.up)) {
198             touchscreen.vpad.on = true;
199         }
200         if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) {
201             touchscreen.vpad.on = false;
202         }
203
204         if (prev_vpad.left != touchscreen.vpad.left
205                 || prev_vpad.right != touchscreen.vpad.right
206                 || prev_vpad.up != touchscreen.vpad.up
207                 || prev_vpad.down != touchscreen.vpad.down
208                 || prev_vpad.on != touchscreen.vpad.on) {
209             if (FETCH_WCB(*window, Special)) {
210                 if (prev_vpad.left == false && touchscreen.vpad.left == true) {
211                     INVOKE_WCB(*window, Special, (GLUT_KEY_LEFT, x, y));
212                 }
213                 else if (prev_vpad.right == false && touchscreen.vpad.right == true) {
214                     INVOKE_WCB(*window, Special, (GLUT_KEY_RIGHT, x, y));
215                 }
216                 else if (prev_vpad.up == false && touchscreen.vpad.up == true) {
217                     INVOKE_WCB(*window, Special, (GLUT_KEY_UP, x, y));
218                 }
219                 else if (prev_vpad.down == false && touchscreen.vpad.down == true) {
220                     INVOKE_WCB(*window, Special, (GLUT_KEY_DOWN, x, y));
221                 }
222             }
223             if (FETCH_WCB(*window, SpecialUp)) {
224                 if (prev_vpad.left == true && touchscreen.vpad.left == false) {
225                     INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_LEFT, x, y));
226                 }
227                 if (prev_vpad.right == true && touchscreen.vpad.right == false) {
228                     INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_RIGHT, x, y));
229                 }
230                 if (prev_vpad.up == true && touchscreen.vpad.up == false) {
231                     INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_UP, x, y));
232                 }
233                 if (prev_vpad.down == true && touchscreen.vpad.down == false) {
234                     INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_DOWN, x, y));
235                 }
236             }
237             handled = true;
238         }
239     }
240
241     /* Normal mouse events */
242     if (!handled && !touchscreen.vpad.on) {
243         window->State.MouseX = x;
244         window->State.MouseY = y;
245
246         if(eventType == SCREEN_EVENT_MTOUCH_MOVE) {
247             INVOKE_WCB(*window, Motion, (x, y));
248         } else if(FETCH_WCB(*window, Mouse)) {
249             touchscreen.in_mmotion = eventType == SCREEN_EVENT_MTOUCH_TOUCH;
250             int glutTouchType = eventType == SCREEN_EVENT_MTOUCH_TOUCH ? GLUT_DOWN : GLUT_UP;
251             INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, glutTouchType, x, y));
252         }
253     }
254 }
255
256 void fgPlatformProcessSingleEvent ( void )
257 {
258     int domain;
259     bps_event_t** eventPtr = &fgStructure.CurrentWindow->Window.pContext.event; //XXX Is there a more direct way to access the context?
260     bps_event_t* event;
261     do
262     {
263         if(*eventPtr != NULL) {
264             SFG_Window* window = fgStructure.CurrentWindow;
265             if (window != NULL && window->Window.Handle != NULL) {
266                 int size[2];
267                 screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);
268                 fghOnReshapeNotify(window,size[0],size[1],GL_FALSE);
269             }
270
271             event = *eventPtr;
272             domain = bps_event_get_domain(event);
273             if (domain == screen_get_domain()) {
274                 int eventType;
275                 screen_event_t screenEvent = screen_event_get_event(event);
276                 screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType);
277                 switch (eventType) {
278
279                 //Mostly from fg_main_android
280                 case SCREEN_EVENT_MTOUCH_TOUCH:
281                 case SCREEN_EVENT_MTOUCH_RELEASE:
282                 case SCREEN_EVENT_MTOUCH_MOVE:
283                 {
284                     mtouch_event_t touchEvent;
285                     screen_get_mtouch_event(screenEvent, &touchEvent, 0);
286                     LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id));
287                     if(touchEvent.contact_id == 0) {
288                         int size[2];
289                         screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);
290                         handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window);
291                     }
292
293                     //Now handle mutlitouch (adapted from fg_main_windows)
294                     if (eventType == SCREEN_EVENT_MTOUCH_TOUCH) {
295                         INVOKE_WCB( *window, MultiEntry,  ( touchEvent.contact_id, GLUT_ENTERED ) );
296                         INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_DOWN ) );
297                     } else if (eventType == SCREEN_EVENT_MTOUCH_MOVE) {
298                         INVOKE_WCB( *window, MultiMotion, ( touchEvent.contact_id, touchEvent.x, touchEvent.y ) );
299                         //XXX No motion is performed without contact, thus MultiPassive is never used
300                     } else if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) {
301                         INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) );
302                         INVOKE_WCB( *window, MultiEntry,  ( touchEvent.contact_id, GLUT_LEFT ) );
303                     }
304                     break;
305                 }
306
307                 case SCREEN_EVENT_POINTER:
308                 {
309                     //Based off/part taken from GamePlay3d PlatformBlackBerry
310                     static int mouse_pressed = 0;
311                     int buttons;
312                     int position[2];
313                     int wheel;
314                     // A move event will be fired unless a button state changed.
315                     bool move = true;
316                     bool left_move = false;
317                     // This is a mouse move event, it is applicable to a device with a usb mouse or simulator.
318                     screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons);
319                     screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position);
320                     screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel);
321                     int size[2];
322                     screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);
323
324                     LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel));
325
326                     //XXX Should multitouch be handled?
327
328                     // Handle left mouse. Interpret as touch if the left mouse event is not consumed.
329                     if (buttons & SCREEN_LEFT_MOUSE_BUTTON) {
330                         if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) {
331                             left_move = true;
332                         } else {
333                             move = false;
334                             mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON;
335                             handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window);
336                         }
337                     } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) {
338                         move = false;
339                         mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON;
340                         handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window);
341                     }
342
343                     // Handle right mouse.
344                     if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) {
345                         if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) {
346                             move = false;
347                             mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON;
348                             INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1]));
349                         }
350                     } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) {
351                         move = false;
352                         mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON;
353                         INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1]));
354                     }
355
356                     // Handle middle mouse.
357                     if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) {
358                         if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) {
359                             move = false;
360                             mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON;
361                             INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1]));
362                         }
363                     } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) {
364                         move = false;
365                         mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON;
366                         INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1]));
367                     }
368
369                     // Fire a move event if none of the buttons changed.
370                     if (left_move || move) {
371                         handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window);
372                     }
373
374                     if (wheel) {
375                         fgState.MouseWheelTicks -= wheel;
376                         //TODO: Implement wheel support (based on fg_main_mswin... though it seems excessive)
377                     }
378                     break;
379                 }
380
381                 //Based off fg_main_android
382                 case SCREEN_EVENT_KEYBOARD:
383                 {
384                     int flags;
385                     int value;
386                     screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags);
387                     screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value);
388                     LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value));
389                     // Suppress key repeats if desired
390                     if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_ON && !fgStructure.CurrentWindow->State.IgnoreKeyRepeat)) {
391                         unsigned int keypress = 0;
392                         unsigned char ascii = 0;
393                         if ((keypress = key_special(value))) {
394                             if(flags & KEY_DOWN) {
395                                 INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY));
396                             } else {
397                                 INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY));
398                             }
399                         } else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) {
400                             if(flags & KEY_DOWN) {
401                                 INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY));
402                             } else {
403                                 INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY));
404                             }
405                         }
406                     }
407                     break;
408                 }
409
410                 case SCREEN_EVENT_PROPERTY:
411                 case SCREEN_EVENT_IDLE:
412                     break;
413
414                 default:
415                     LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType));
416                     break;
417                 }
418             } else if (domain == navigator_get_domain()) {
419                 int eventType = bps_event_get_code(event);
420                 switch (eventType) {
421
422                 case NAVIGATOR_WINDOW_STATE:
423                 {
424                     LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE");
425                     navigator_window_state_t state = navigator_event_get_window_state(event);
426                     switch (state)
427                     {
428                     case NAVIGATOR_WINDOW_FULLSCREEN:
429                         LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN");
430                         INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME));
431                         break;
432                     case NAVIGATOR_WINDOW_THUMBNAIL:
433                     case NAVIGATOR_WINDOW_INVISIBLE:
434                         LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE");
435                         INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE));
436                         break;
437                     default:
438                         LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state));
439                         break;
440                     }
441                     break;
442                 }
443
444                 case NAVIGATOR_EXIT:
445                 {
446                     LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT");
447                     /* User closed the application for good, let's kill the window */
448                     SFG_Window* window = fgStructure.CurrentWindow;
449                     if (window != NULL) {
450                         fgDestroyWindow(window);
451                     } else {
452                         LOGW("NAVIGATOR_EXIT: No current window");
453                     }
454                     break;
455                 }
456
457                 case NAVIGATOR_SWIPE_DOWN:
458                 case NAVIGATOR_BACK:
459                 case NAVIGATOR_WINDOW_ACTIVE:
460                 case NAVIGATOR_DEVICE_LOCK_STATE:
461                 case NAVIGATOR_WINDOW_COVER:
462                 case NAVIGATOR_WINDOW_COVER_ENTER:
463                 case NAVIGATOR_WINDOW_COVER_EXIT:
464                     //XXX Should probably do something with these
465                     break;
466
467                 default:
468                     LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType));
469                     break;
470                 }
471             }
472         }
473     } while(bps_get_event(eventPtr, 1) == BPS_SUCCESS && *eventPtr != NULL);
474
475     /* Reset event to reduce chances of triggering something */
476     *eventPtr = NULL;
477 }
478
479 void fgPlatformMainLoopPreliminaryWork ( void )
480 {
481     LOGI("fgPlatformMainLoopPreliminaryWork");
482 }
483
484
485 /* deal with work list items */
486 void fgPlatformInitWork(SFG_Window* window)
487 {
488     /* notify windowStatus/visibility */
489     INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
490
491     /* Position callback, always at 0,0 */
492     fghOnPositionNotify(window, 0, 0, GL_TRUE);
493
494     /* Size gets notified on window creation with size detection in mainloop above
495      * XXX CHECK: does this messages happen too early like on windows,
496      * so client code cannot have registered a callback yet and the message
497      * is thus never received by client?
498      */
499 }
500
501 void fgPlatformPosResZordWork(SFG_Window* window, unsigned int workMask)
502 {
503     if (workMask & GLUT_FULL_SCREEN_WORK)
504         fgPlatformFullScreenToggle( window );
505     if (workMask & GLUT_POSITION_WORK)
506         fgPlatformPositionWindow( window, window->State.DesiredXpos, window->State.DesiredYpos );
507     if (workMask & GLUT_SIZE_WORK)
508         fgPlatformReshapeWindow ( window, window->State.DesiredWidth, window->State.DesiredHeight );
509     if (workMask & GLUT_ZORDER_WORK)
510     {
511         if (window->State.DesiredZOrder < 0)
512             fgPlatformPushWindow( window );
513         else
514             fgPlatformPopWindow( window );
515     }
516 }
517
518 void fgPlatformVisibilityWork(SFG_Window* window)
519 {
520     /* Visibility status of window should get updated in the window message handlers
521      * For now, none of these functions called below do anything, so don't worry
522      * about it
523      */
524     SFG_Window *win = window;
525     switch (window->State.DesiredVisibility)
526     {
527     case DesireHiddenState:
528         fgPlatformHideWindow( window );
529         break;
530     case DesireIconicState:
531         /* Call on top-level window */
532         while (win->Parent)
533             win = win->Parent;
534         fgPlatformIconifyWindow( win );
535         break;
536     case DesireNormalState:
537         fgPlatformShowWindow( window );
538         break;
539     }
540 }
541