- fixed redraw for copy button in new themes editor
[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         GHOST_TEventType type= GHOST_GetEventType(evt);
374
375         if (type == GHOST_kEventQuit) {
376                 exit_usiblender();
377         } else {
378                 GHOST_WindowHandle ghostwin= GHOST_GetEventWindow(evt);
379                 GHOST_TEventDataPtr data= GHOST_GetEventData(evt);
380                 Window *win;
381                 
382                 if (!ghostwin) {
383                         printf("GHOST event error - no window - type: %d\n", type);
384                         return 1;
385                 } else if (!GHOST_ValidWindow(g_system, ghostwin)) {
386                         printf("GHOST event error - invalid window - win: %p\n", ghostwin);
387                         return 1;
388                 } else {
389                         win= GHOST_GetWindowUserData(ghostwin);
390                 }
391                 
392                 switch (type) {
393                 case GHOST_kEventCursorMove: {
394                         GHOST_TEventCursorData *cd= data;
395                         int cx, cy;
396                         
397                         GHOST_ScreenToClient(win->ghostwin, cd->x, cd->y, &cx, &cy);
398                         win->lmouse[0]= cx;
399                         win->lmouse[1]= (win->size[1]-1) - cy;
400                         
401                         window_handle(win, MOUSEX, win->lmouse[0]);
402                         window_handle(win, MOUSEY, win->lmouse[1]);
403
404                         break;
405                 }
406                 case GHOST_kEventButtonDown:
407                 case GHOST_kEventButtonUp: {
408                         GHOST_TEventButtonData *bd= data;
409                         int val= (type==GHOST_kEventButtonDown);
410                         int bbut= convert_mbut(bd->button);
411                 
412                         if (bbut==LEFTMOUSE) {
413                                 if (val) {
414                                         if (win->commandqual) {
415                                                 bbut= win->faked_mbut= RIGHTMOUSE;
416                                         } else if ((win->lqual & LR_ALTKEY) && (U.flag & TWOBUTTONMOUSE)) {
417                                                 /* finally, it actually USES the userpref! :) -intrr */
418                                                 bbut= win->faked_mbut= MIDDLEMOUSE;
419                                         }
420                                 } else {
421                                         if (win->faked_mbut) {
422                                                 bbut= win->faked_mbut;
423                                                 win->faked_mbut= 0;
424                                         }
425                                 }
426                         }
427
428                         if (bbut==LEFTMOUSE) {
429                                 win->lmbut= change_bit(win->lmbut, L_MOUSE, val);
430                         } else if (bbut==MIDDLEMOUSE) {
431                                 win->lmbut= change_bit(win->lmbut, M_MOUSE, val);
432                         } else {
433                                 win->lmbut= change_bit(win->lmbut, R_MOUSE, val);
434                         }
435                         window_handle(win, bbut, val);
436                         
437                         break;
438                 }
439         
440                 case GHOST_kEventKeyDown:
441                 case GHOST_kEventKeyUp: {
442                         GHOST_TEventKeyData *kd= data;
443                         int val= (type==GHOST_kEventKeyDown);
444                         int bkey= convert_key(kd->key);
445
446                         if (kd->key == GHOST_kKeyCommand) {
447                                 win->commandqual= val;
448                         }
449
450                         if (bkey) {
451                                 if (bkey==LEFTSHIFTKEY || bkey==RIGHTSHIFTKEY) {
452                                         win->lqual= change_bit(win->lqual, LR_SHIFTKEY, val);
453                                 } else if (bkey==LEFTCTRLKEY || bkey==RIGHTCTRLKEY) {
454                                         win->lqual= change_bit(win->lqual, LR_CTRLKEY, val);
455                                 } else if (bkey==LEFTALTKEY || bkey==RIGHTALTKEY) {
456                                         win->lqual= change_bit(win->lqual, LR_ALTKEY, val);
457                                 }
458
459                                 window_handle_ext(win, bkey, val, kd->ascii);
460                         }
461                         
462                         break;
463                 }
464
465                 case GHOST_kEventWheel: {
466                         GHOST_TEventWheelData* wheelData = (GHOST_TEventWheelData*) data;
467                         if (wheelData->z > 0) {
468                                 window_handle(win, WHEELUPMOUSE, 1);
469                         } else {
470                                 window_handle(win, WHEELDOWNMOUSE, 1);
471                         }
472                         break;
473                 }
474
475                 case GHOST_kEventWindowDeactivate:
476                 case GHOST_kEventWindowActivate: {
477                         win->active= (type==GHOST_kEventWindowActivate);
478                         window_handle(win, INPUTCHANGE, win->active);
479                         
480                         if (win->active) {
481                                 if ((win->lqual & LR_SHIFTKEY) && !query_qual('s')) {
482                                         win->lqual= change_bit(win->lqual, LR_SHIFTKEY, 0);
483                                         window_handle(win, LEFTSHIFTKEY, 0);
484                                 }
485                                 if ((win->lqual & LR_CTRLKEY) && !query_qual('c')) {
486                                         win->lqual= change_bit(win->lqual, LR_CTRLKEY, 0);
487                                         window_handle(win, LEFTCTRLKEY, 0);
488                                 }
489                                 if ((win->lqual & LR_ALTKEY) && !query_qual('a')) {
490                                         win->lqual= change_bit(win->lqual, LR_ALTKEY, 0);
491                                         window_handle(win, LEFTALTKEY, 0);
492                                 }
493                                 win->commandqual= query_qual('C');
494
495                                 /* 
496                                  * XXX quick hack so OSX version works better
497                                  * when the window is clicked on (focused).
498                                  *
499                                  * it used to pass on the old win->lmouse value,
500                                  * which causes a wrong click in Blender.
501                                  * Actually, a 'focus' click should not be passed
502                                  * on to blender... (ton)
503                                  */
504                                 if(1) { /* enables me to add locals */
505                                         int cx, cy, wx, wy;
506                                         GHOST_GetCursorPosition(g_system, &wx, &wy);
507
508                                         GHOST_ScreenToClient(win->ghostwin, wx, wy, &cx, &cy);
509                                         win->lmouse[0]= cx;
510                                         win->lmouse[1]= (win->size[1]-1) - cy;
511                                         window_handle(win, MOUSEX, win->lmouse[0]);
512                                         window_handle(win, MOUSEY, win->lmouse[1]);
513                                 }
514                         }
515                         
516                         break;
517                 }
518                 case GHOST_kEventWindowClose: {
519                         window_handle(win, WINCLOSE, 1);
520                         break;
521                 }
522                 case GHOST_kEventWindowUpdate: {
523                         window_handle(win, REDRAW, 1);
524                         break;
525                 }
526                 case GHOST_kEventWindowSize: {
527                         GHOST_RectangleHandle client_rect;
528                         int l, t, r, b, scr_w, scr_h;
529
530                         client_rect= GHOST_GetClientBounds(win->ghostwin);
531                         GHOST_GetRectangle(client_rect, &l, &t, &r, &b);
532                         
533                         GHOST_DisposeRectangle(client_rect);
534                         
535                         winlay_get_screensize(&scr_w, &scr_h);
536                         win->position[0]= l;
537                         win->position[1]= scr_h - b - 1;
538                         win->size[0]= r-l;
539                         win->size[1]= b-t;
540
541                         window_handle(win, RESHAPE, 1);
542                         break;
543                 }
544                 }
545         }
546
547         return 1;
548 }
549
550 char *window_get_title(Window *win) {
551         char *title= GHOST_GetTitle(win->ghostwin);
552         char *mem_title= BLI_strdup(title);
553         free(title);
554
555         return mem_title;
556 }
557
558 void window_set_title(Window *win, char *title) {
559         GHOST_SetTitle(win->ghostwin, title);
560 }
561
562 short window_get_qual(Window *win) {
563         return win->lqual;
564 }
565
566 short window_get_mbut(Window *win) {
567         return win->lmbut;
568 }
569
570 void window_get_mouse(Window *win, short *mval) {
571         mval[0]= win->lmouse[0];
572         mval[1]= win->lmouse[1];
573 }
574
575 void window_get_position(Window *win, int *posx_r, int *posy_r) {
576         *posx_r= win->position[0];
577         *posy_r= win->position[1];
578 }
579
580 void window_get_size(Window *win, int *width_r, int *height_r) {
581         *width_r= win->size[0];
582         *height_r= win->size[1];
583 }
584
585 void window_set_size(Window *win, int width, int height) {
586         GHOST_SetClientSize(win->ghostwin, width, height);
587 }
588
589 void window_lower(Window *win) {
590         GHOST_SetWindowOrder(win->ghostwin, GHOST_kWindowOrderBottom);
591 }
592
593 void window_raise(Window *win) {
594         GHOST_SetWindowOrder(win->ghostwin, GHOST_kWindowOrderTop);
595 }
596
597 #ifdef _WIN32   //FULLSCREEN
598 void window_toggle_fullscreen(Window *win, int fullscreen) {
599         /* these two lines make sure front and backbuffer are equal. for swapbuffers */
600         markdirty_all();
601         screen_swapbuffers();
602
603         if(fullscreen)
604                 GHOST_SetWindowState(win->ghostwin, GHOST_kWindowStateFullScreen);
605         else
606                 GHOST_SetWindowState(win->ghostwin, GHOST_kWindowStateMaximized);
607 }
608 #endif
609
610 void window_warp_pointer(Window *win, int x, int y) {
611         y= win->size[1] - y - 1;
612         GHOST_ClientToScreen(win->ghostwin, x, y, &x, &y);
613         GHOST_SetCursorPosition(g_system, x, y);
614 }
615
616 void window_queue_redraw(Window *win) {
617         GHOST_InvalidateWindow(win->ghostwin); // ghost will send back a redraw to blender
618 }
619
620 /***/
621
622 void winlay_process_events(int wait_for_event) {
623         GHOST_ProcessEvents(g_system, wait_for_event);
624         GHOST_DispatchEvents(g_system);
625 }
626
627 void winlay_get_screensize(int *width_r, int *height_r) {
628         unsigned int uiwidth;
629         unsigned int uiheight;
630         
631         if (!g_system) {
632                 GHOST_EventConsumerHandle consumer= GHOST_CreateEventConsumer(event_proc, NULL);
633         
634                 g_system= GHOST_CreateSystem();
635                 GHOST_AddEventConsumer(g_system, consumer);
636         }
637         
638         GHOST_GetMainDisplayDimensions(g_system, &uiwidth, &uiheight);
639         *width_r= uiwidth;
640         *height_r= uiheight;
641 }
642
643 Window *winlay_get_active_window(void) {
644         return active_gl_window;
645 }