- fixed colors of ipokeys in 3d window
[blender.git] / source / blender / src / ghostwinlay.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32 #include <stdlib.h>
33 #include <stdio.h>
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #ifdef WIN32
40 #include "BLI_winstuff.h"
41 #endif
42
43 #include "MEM_guardedalloc.h"
44
45 #include "DNA_listBase.h"       
46 #include "DNA_userdef_types.h"  /* U.flag & TWOBUTTONMOUSE */
47
48 #include "BLI_blenlib.h"
49
50 #include "GHOST_C-api.h"
51
52 #include "BKE_utildefines.h"
53 #include "BKE_global.h"
54
55 #include "BIF_gl.h"
56 #include "BIF_graphics.h"
57 #include "BIF_mywindow.h"
58 #include "BIF_screen.h"
59 #include "BIF_usiblender.h"
60
61 #include "mydevice.h"
62 #include "blendef.h"
63
64 #include "winlay.h"
65
66 static GHOST_SystemHandle g_system= 0;
67
68         /* Some simple ghost <-> blender conversions */
69         
70 static GHOST_TStandardCursor convert_cursor(int curs) {
71         switch(curs) {
72         default:
73         case CURSOR_STD:                return GHOST_kStandardCursorDefault;
74         case CURSOR_VPAINT:             return GHOST_kStandardCursorRightArrow;
75         case CURSOR_FACESEL:            return GHOST_kStandardCursorRightArrow;
76         case CURSOR_WAIT:               return GHOST_kStandardCursorWait;
77         case CURSOR_EDIT:               return GHOST_kStandardCursorCrosshair;
78         case CURSOR_HELP:               return GHOST_kStandardCursorHelp;
79         case CURSOR_X_MOVE:             return GHOST_kStandardCursorLeftRight;
80         case CURSOR_Y_MOVE:             return GHOST_kStandardCursorUpDown;
81         case CURSOR_PENCIL:             return GHOST_kStandardCursorPencil;
82         }
83 }
84
85 static int convert_mbut(GHOST_TButtonMask but) {
86         if (but == GHOST_kButtonMaskLeft) {
87                 return LEFTMOUSE;
88         } else if (but == GHOST_kButtonMaskRight) {
89                 return RIGHTMOUSE;
90         } else {
91                 return MIDDLEMOUSE;
92         }
93 }
94
95 static int convert_key(GHOST_TKey key) {
96         if (key>=GHOST_kKeyA && key<=GHOST_kKeyZ) {
97                 return (AKEY + ((int) key - GHOST_kKeyA));
98         } else if (key>=GHOST_kKey0 && key<=GHOST_kKey9) {
99                 return (ZEROKEY + ((int) key - GHOST_kKey0));
100         } else if (key>=GHOST_kKeyNumpad0 && key<=GHOST_kKeyNumpad9) {
101                 return (PAD0 + ((int) key - GHOST_kKeyNumpad0));
102         } else if (key>=GHOST_kKeyF1 && key<=GHOST_kKeyF12) {
103                 return (F1KEY + ((int) key - GHOST_kKeyF1));
104         } else {
105                 switch (key) {
106                 case GHOST_kKeyBackSpace:               return BACKSPACEKEY;
107                 case GHOST_kKeyTab:                             return TABKEY;
108                 case GHOST_kKeyLinefeed:                return LINEFEEDKEY;
109                 case GHOST_kKeyClear:                   return 0;
110                 case GHOST_kKeyEnter:                   return RETKEY;
111         
112                 case GHOST_kKeyEsc:                             return ESCKEY;
113                 case GHOST_kKeySpace:                   return SPACEKEY;
114                 case GHOST_kKeyQuote:                   return QUOTEKEY;
115                 case GHOST_kKeyComma:                   return COMMAKEY;
116                 case GHOST_kKeyMinus:                   return MINUSKEY;
117                 case GHOST_kKeyPeriod:                  return PERIODKEY;
118                 case GHOST_kKeySlash:                   return SLASHKEY;
119
120                 case GHOST_kKeySemicolon:               return SEMICOLONKEY;
121                 case GHOST_kKeyEqual:                   return EQUALKEY;
122
123                 case GHOST_kKeyLeftBracket:             return LEFTBRACKETKEY;
124                 case GHOST_kKeyRightBracket:    return RIGHTBRACKETKEY;
125                 case GHOST_kKeyBackslash:               return BACKSLASHKEY;
126                 case GHOST_kKeyAccentGrave:             return ACCENTGRAVEKEY;
127
128                 case GHOST_kKeyLeftShift:               return LEFTSHIFTKEY;
129                 case GHOST_kKeyRightShift:              return RIGHTSHIFTKEY;
130                 case GHOST_kKeyLeftControl:             return LEFTCTRLKEY;
131                 case GHOST_kKeyRightControl:    return RIGHTCTRLKEY;
132                 case GHOST_kKeyLeftAlt:                 return LEFTALTKEY;
133                 case GHOST_kKeyRightAlt:                return RIGHTALTKEY;
134
135                 case GHOST_kKeyCapsLock:                return CAPSLOCKKEY;
136                 case GHOST_kKeyNumLock:                 return 0;
137                 case GHOST_kKeyScrollLock:              return 0;
138
139                 case GHOST_kKeyLeftArrow:               return LEFTARROWKEY;
140                 case GHOST_kKeyRightArrow:              return RIGHTARROWKEY;
141                 case GHOST_kKeyUpArrow:                 return UPARROWKEY;
142                 case GHOST_kKeyDownArrow:               return DOWNARROWKEY;
143
144                 case GHOST_kKeyPrintScreen:             return 0;
145                 case GHOST_kKeyPause:                   return PAUSEKEY;
146
147                 case GHOST_kKeyInsert:                  return INSERTKEY;
148                 case GHOST_kKeyDelete:                  return DELKEY;
149                 case GHOST_kKeyHome:                    return HOMEKEY;
150                 case GHOST_kKeyEnd:                             return ENDKEY;
151                 case GHOST_kKeyUpPage:                  return PAGEUPKEY;
152                 case GHOST_kKeyDownPage:                return PAGEDOWNKEY;
153
154                 case GHOST_kKeyNumpadPeriod:    return PADPERIOD;
155                 case GHOST_kKeyNumpadEnter:             return PADENTER;
156                 case GHOST_kKeyNumpadPlus:              return PADPLUSKEY;
157                 case GHOST_kKeyNumpadMinus:             return PADMINUS;
158                 case GHOST_kKeyNumpadAsterisk:  return PADASTERKEY;
159                 case GHOST_kKeyNumpadSlash:             return PADSLASHKEY;
160                 case GHOST_kKeyUnknown:                 return UNKNOWNKEY;
161
162                 default:
163                         return 0;
164                 }
165         }
166 }
167
168         /***/
169         
170 struct _Window {
171         GHOST_WindowHandle      ghostwin;
172         
173                 /* Handler and private data for handler */
174         WindowHandlerFP         handler;
175         void                            *user_data;
176         
177                 /* Window state */
178         int             size[2], position[2];
179         int             active, visible;
180         
181                 /* Last known mouse/button/qualifier state */
182         int             lmouse[2];
183         int             lqual;          /* (LR_SHFTKEY, LR_CTRLKEY, LR_ALTKEY) */
184         int             lmbut;          /* (L_MOUSE, M_MOUSE, R_MOUSE) */
185         int             commandqual;
186
187                 /* Tracks the faked mouse button, if non-zero it is
188                  * the event number of the last faked button.
189                  */
190         int             faked_mbut;
191
192         GHOST_TimerTaskHandle   timer;
193         int                                             timer_event;
194 };
195
196 static Window *window_new(GHOST_WindowHandle ghostwin)
197 {
198         Window *win= MEM_callocN(sizeof(*win), "Window");
199         win->ghostwin= ghostwin;
200         
201         return win;
202 }
203
204 static void window_handle(Window *win, short event, short val)
205 {
206         if (win->handler) {
207                 win->handler(win, win->user_data, event, val, 0);
208         }
209 }
210
211 static void window_handle_ext(Window *win, short event, short val, short extra)
212 {
213         if (win->handler) {
214                 win->handler(win, win->user_data, event, val, extra);
215         }
216 }
217
218 static void window_free(Window *win) 
219 {
220         MEM_freeN(win);
221 }
222
223         /***/
224
225 static Window *active_gl_window= NULL;
226
227 Window *window_open(char *title, int posx, int posy, int sizex, int sizey, int start_maximized)
228 {
229         GHOST_WindowHandle ghostwin;
230         GHOST_TWindowState inital_state;
231         int scr_w, scr_h;
232
233         winlay_get_screensize(&scr_w, &scr_h);
234         if(G.f & G_DEBUG) {
235                 printf("screen size %d %d\n", scr_w, scr_h);    
236                 printf("win start %d %d size %d %d\n",  posx,  posy,  sizex,  sizey);
237         }
238         posy= (scr_h-posy-sizey);
239         
240         /* create a fullscreen window on unix by default*/
241 #if !defined(WIN32) && !defined(__APPLE__)
242         inital_state= start_maximized?
243                 GHOST_kWindowStateFullScreen:GHOST_kWindowStateNormal;
244 #else
245 #ifdef _WIN32   // FULLSCREEN
246         if (start_maximized == G_WINDOWSTATE_FULLSCREEN)
247                 inital_state= GHOST_kWindowStateFullScreen;
248         else
249                 inital_state= start_maximized?GHOST_kWindowStateMaximized:GHOST_kWindowStateNormal;
250 #else                   // APPLE
251         inital_state= start_maximized?GHOST_kWindowStateMaximized:GHOST_kWindowStateNormal;
252 #endif
253 #endif
254
255         ghostwin= GHOST_CreateWindow(g_system, 
256                                                                 title, 
257                                                                 posx, posy, sizex, sizey, 
258                                                                 inital_state, 
259                                                                 GHOST_kDrawingContextTypeOpenGL,
260                                                                 0 /* no stereo */);
261         
262         if (ghostwin) {
263                 Window *win= window_new(ghostwin);
264                 
265                 if (win) {
266                         GHOST_SetWindowUserData(ghostwin, win);
267                         
268                         win->position[0]= posx;
269                         win->position[1]= posy;
270                         win->size[0]= sizex;
271                         win->size[1]= sizey;
272                         
273                         win->lmouse[0]= win->size[0]/2;
274                         win->lmouse[1]= win->size[1]/2;
275                 } else {
276                         GHOST_DisposeWindow(g_system, ghostwin);
277                 }
278                 
279                 return win;
280         } else {
281                 return NULL;
282         }
283 }
284
285 void window_set_handler(Window *win, WindowHandlerFP handler, void *user_data)
286 {
287         win->handler= handler;
288         win->user_data= user_data;
289 }
290
291 static void window_timer_proc(GHOST_TimerTaskHandle timer, GHOST_TUns64 time)
292 {
293         Window *win= GHOST_GetTimerTaskUserData(timer);
294
295         win->handler(win, win->user_data, win->timer_event, 0, 0);
296 }
297
298 void window_set_timer(Window *win, int delay_ms, int event)
299 {
300         if (win->timer) GHOST_RemoveTimer(g_system, win->timer);
301
302         win->timer_event= event;
303         win->timer= GHOST_InstallTimer(g_system, delay_ms, delay_ms, window_timer_proc, win);
304 }
305
306 void window_destroy(Window *win) {
307         if (active_gl_window==win) {
308                 active_gl_window= NULL;
309         }
310         
311         if (win->timer) {
312                 GHOST_RemoveTimer(g_system, win->timer);
313                 win->timer= NULL;
314         }
315
316         GHOST_DisposeWindow(g_system, win->ghostwin);
317         window_free(win);
318 }
319
320 void window_set_cursor(Window *win, int curs) {
321         if (curs==CURSOR_NONE) {
322                 GHOST_SetCursorVisibility(win->ghostwin, 0);
323         } else {
324                 GHOST_SetCursorVisibility(win->ghostwin, 1);
325                 GHOST_SetCursorShape(win->ghostwin, convert_cursor(curs));
326         }
327 }
328
329 void window_set_custom_cursor(Window *win, unsigned char mask[16][2], unsigned char bitmap[16][2]) {
330         GHOST_SetCustomCursorShape(win->ghostwin, bitmap, mask, 7, 7);
331 }
332
333 void window_make_active(Window *win) {
334         if (win != active_gl_window) {
335                 active_gl_window= win;
336                 GHOST_ActivateWindowDrawingContext(win->ghostwin);
337         }
338 }
339
340 void window_swap_buffers(Window *win) {
341         GHOST_SwapWindowBuffers(win->ghostwin);
342 }
343
344 static int query_qual(char qual) {
345         GHOST_TModifierKeyMask left, right;
346         int val= 0;
347         
348         if (qual=='s') {
349                 left= GHOST_kModifierKeyLeftShift;
350                 right= GHOST_kModifierKeyRightShift;
351         } else if (qual=='c') {
352                 left= GHOST_kModifierKeyLeftControl;
353                 right= GHOST_kModifierKeyRightControl;
354         } else if (qual=='C') {
355                 left= right= GHOST_kModifierKeyCommand;
356         } else {
357                 left= GHOST_kModifierKeyLeftAlt;
358                 right= GHOST_kModifierKeyRightAlt;
359         }
360
361         GHOST_GetModifierKeyState(g_system, left, &val);
362         if (!val)
363                 GHOST_GetModifierKeyState(g_system, right, &val);
364         
365         return val;
366 }
367
368 static int change_bit(int val, int bit, int to_on) {
369         return to_on?(val|bit):(val&~bit);
370 }
371
372 static int event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private) 
373 {
374         GHOST_TEventType type= GHOST_GetEventType(evt);
375
376         if (type == GHOST_kEventQuit) {
377                 exit_usiblender();
378         } else {
379                 GHOST_WindowHandle ghostwin= GHOST_GetEventWindow(evt);
380                 GHOST_TEventDataPtr data= GHOST_GetEventData(evt);
381                 Window *win;
382                 
383                 if (!ghostwin) {
384                         printf("GHOST event error - no window - type: %d\n", type);
385                         return 1;
386                 } else if (!GHOST_ValidWindow(g_system, ghostwin)) {
387                         printf("GHOST event error - invalid window - win: %p\n", ghostwin);
388                         return 1;
389                 } else {
390                         win= GHOST_GetWindowUserData(ghostwin);
391                 }
392                 
393                 switch (type) {
394                 case GHOST_kEventCursorMove: {
395                         GHOST_TEventCursorData *cd= data;
396                         int cx, cy;
397                         
398                         GHOST_ScreenToClient(win->ghostwin, cd->x, cd->y, &cx, &cy);
399                         win->lmouse[0]= cx;
400                         win->lmouse[1]= (win->size[1]-1) - cy;
401                         
402                         window_handle(win, MOUSEX, win->lmouse[0]);
403                         window_handle(win, MOUSEY, win->lmouse[1]);
404
405                         break;
406                 }
407                 case GHOST_kEventButtonDown:
408                 case GHOST_kEventButtonUp: {
409                         GHOST_TEventButtonData *bd= data;
410                         int val= (type==GHOST_kEventButtonDown);
411                         int bbut= convert_mbut(bd->button);
412                 
413                         if (bbut==LEFTMOUSE) {
414                                 if (val) {
415                                         if (win->commandqual) {
416                                                 bbut= win->faked_mbut= RIGHTMOUSE;
417                                         } else if ((win->lqual & LR_ALTKEY) && (U.flag & TWOBUTTONMOUSE)) {
418                                                 /* finally, it actually USES the userpref! :) -intrr */
419                                                 bbut= win->faked_mbut= MIDDLEMOUSE;
420                                         }
421                                 } else {
422                                         if (win->faked_mbut) {
423                                                 bbut= win->faked_mbut;
424                                                 win->faked_mbut= 0;
425                                         }
426                                 }
427                         }
428
429                         if (bbut==LEFTMOUSE) {
430                                 win->lmbut= change_bit(win->lmbut, L_MOUSE, val);
431                         } else if (bbut==MIDDLEMOUSE) {
432                                 win->lmbut= change_bit(win->lmbut, M_MOUSE, val);
433                         } else {
434                                 win->lmbut= change_bit(win->lmbut, R_MOUSE, val);
435                         }
436                         window_handle(win, bbut, val);
437                         
438                         break;
439                 }
440         
441                 case GHOST_kEventKeyDown:
442                 case GHOST_kEventKeyUp: {
443                         GHOST_TEventKeyData *kd= data;
444                         int val= (type==GHOST_kEventKeyDown);
445                         int bkey= convert_key(kd->key);
446
447                         if (kd->key == GHOST_kKeyCommand) {
448                                 win->commandqual= val;
449                         }
450
451                         if (bkey) {
452                                 if (bkey==LEFTSHIFTKEY || bkey==RIGHTSHIFTKEY) {
453                                         win->lqual= change_bit(win->lqual, LR_SHIFTKEY, val);
454                                 } else if (bkey==LEFTCTRLKEY || bkey==RIGHTCTRLKEY) {
455                                         win->lqual= change_bit(win->lqual, LR_CTRLKEY, val);
456                                 } else if (bkey==LEFTALTKEY || bkey==RIGHTALTKEY) {
457                                         win->lqual= change_bit(win->lqual, LR_ALTKEY, val);
458                                 }
459
460                                 window_handle_ext(win, bkey, val, kd->ascii);
461                         }
462                         
463                         break;
464                 }
465
466                 case GHOST_kEventWheel: {
467                         GHOST_TEventWheelData* wheelData = (GHOST_TEventWheelData*) data;
468                         if (wheelData->z > 0) {
469                                 window_handle(win, WHEELUPMOUSE, 1);
470                         } else {
471                                 window_handle(win, WHEELDOWNMOUSE, 1);
472                         }
473                         break;
474                 }
475
476                 case GHOST_kEventWindowDeactivate:
477                 case GHOST_kEventWindowActivate: {
478                         win->active= (type==GHOST_kEventWindowActivate);
479                         window_handle(win, INPUTCHANGE, win->active);
480                         
481                         if (win->active) {
482                                 if ((win->lqual & LR_SHIFTKEY) && !query_qual('s')) {
483                                         win->lqual= change_bit(win->lqual, LR_SHIFTKEY, 0);
484                                         window_handle(win, LEFTSHIFTKEY, 0);
485                                 }
486                                 if ((win->lqual & LR_CTRLKEY) && !query_qual('c')) {
487                                         win->lqual= change_bit(win->lqual, LR_CTRLKEY, 0);
488                                         window_handle(win, LEFTCTRLKEY, 0);
489                                 }
490                                 if ((win->lqual & LR_ALTKEY) && !query_qual('a')) {
491                                         win->lqual= change_bit(win->lqual, LR_ALTKEY, 0);
492                                         window_handle(win, LEFTALTKEY, 0);
493                                 }
494                                 win->commandqual= query_qual('C');
495
496                                 /* 
497                                  * XXX quick hack so OSX version works better
498                                  * when the window is clicked on (focused).
499                                  *
500                                  * it used to pass on the old win->lmouse value,
501                                  * which causes a wrong click in Blender.
502                                  * Actually, a 'focus' click should not be passed
503                                  * on to blender... (ton)
504                                  */
505                                 if(1) { /* enables me to add locals */
506                                         int cx, cy, wx, wy;
507                                         GHOST_GetCursorPosition(g_system, &wx, &wy);
508
509                                         GHOST_ScreenToClient(win->ghostwin, wx, wy, &cx, &cy);
510                                         win->lmouse[0]= cx;
511                                         win->lmouse[1]= (win->size[1]-1) - cy;
512                                         window_handle(win, MOUSEX, win->lmouse[0]);
513                                         window_handle(win, MOUSEY, win->lmouse[1]);
514                                 }
515                         }
516                         
517                         break;
518                 }
519                 case GHOST_kEventWindowClose: {
520                         window_handle(win, WINCLOSE, 1);
521                         break;
522                 }
523                 case GHOST_kEventWindowUpdate: {
524                         window_handle(win, REDRAW, 1);
525                         break;
526                 }
527                 case GHOST_kEventWindowSize: {
528                         GHOST_RectangleHandle client_rect;
529                         int l, t, r, b, scr_w, scr_h;
530
531                         client_rect= GHOST_GetClientBounds(win->ghostwin);
532                         GHOST_GetRectangle(client_rect, &l, &t, &r, &b);
533                         
534                         GHOST_DisposeRectangle(client_rect);
535                         
536                         winlay_get_screensize(&scr_w, &scr_h);
537                         win->position[0]= l;
538                         win->position[1]= scr_h - b - 1;
539                         win->size[0]= r-l;
540                         win->size[1]= b-t;
541
542                         window_handle(win, RESHAPE, 1);
543                         break;
544                 }
545         }
546         }
547         
548         return 1;
549 }
550
551 char *window_get_title(Window *win) {
552         char *title= GHOST_GetTitle(win->ghostwin);
553         char *mem_title= BLI_strdup(title);
554         free(title);
555
556         return mem_title;
557 }
558
559 void window_set_title(Window *win, char *title) {
560         GHOST_SetTitle(win->ghostwin, title);
561 }
562
563 short window_get_qual(Window *win) {
564         return win->lqual;
565 }
566
567 short window_get_mbut(Window *win) {
568         return win->lmbut;
569 }
570
571 void window_get_mouse(Window *win, short *mval) {
572         mval[0]= win->lmouse[0];
573         mval[1]= win->lmouse[1];
574 }
575
576 void window_get_position(Window *win, int *posx_r, int *posy_r) {
577         *posx_r= win->position[0];
578         *posy_r= win->position[1];
579 }
580
581 void window_get_size(Window *win, int *width_r, int *height_r) {
582         *width_r= win->size[0];
583         *height_r= win->size[1];
584 }
585
586 void window_set_size(Window *win, int width, int height) {
587         GHOST_SetClientSize(win->ghostwin, width, height);
588 }
589
590 void window_lower(Window *win) {
591         GHOST_SetWindowOrder(win->ghostwin, GHOST_kWindowOrderBottom);
592 }
593
594 void window_raise(Window *win) {
595         GHOST_SetWindowOrder(win->ghostwin, GHOST_kWindowOrderTop);
596 }
597
598 #ifdef _WIN32   //FULLSCREEN
599 void window_toggle_fullscreen(Window *win, int fullscreen) {
600         /* these two lines make sure front and backbuffer are equal. for swapbuffers */
601         markdirty_all();
602         screen_swapbuffers();
603
604         if(fullscreen)
605                 GHOST_SetWindowState(win->ghostwin, GHOST_kWindowStateFullScreen);
606         else
607                 GHOST_SetWindowState(win->ghostwin, GHOST_kWindowStateMaximized);
608 }
609 #endif
610
611 void window_warp_pointer(Window *win, int x, int y) {
612         y= win->size[1] - y - 1;
613         GHOST_ClientToScreen(win->ghostwin, x, y, &x, &y);
614         GHOST_SetCursorPosition(g_system, x, y);
615 }
616
617 void window_queue_redraw(Window *win) {
618         GHOST_InvalidateWindow(win->ghostwin); // ghost will send back a redraw to blender
619 }
620
621 /***/
622
623 void winlay_process_events(int wait_for_event) {
624         GHOST_ProcessEvents(g_system, wait_for_event);
625         GHOST_DispatchEvents(g_system);
626 }
627
628 void winlay_get_screensize(int *width_r, int *height_r) {
629         unsigned int uiwidth;
630         unsigned int uiheight;
631         
632         if (!g_system) {
633                 GHOST_EventConsumerHandle consumer= GHOST_CreateEventConsumer(event_proc, NULL);
634         
635                 g_system= GHOST_CreateSystem();
636                 GHOST_AddEventConsumer(g_system, consumer);
637         }
638         
639         GHOST_GetMainDisplayDimensions(g_system, &uiwidth, &uiheight);
640         *width_r= uiwidth;
641         *height_r= uiheight;
642 }
643
644 Window *winlay_get_active_window(void) {
645         return active_gl_window;
646 }