OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [nanox/] [srvmain.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
 * Copyright (c) 1999, 2000, 2001 Greg Haerr <greg@censoft.com>
3
 * Copyright (c) 1991 David I. Bell
4
 * Permission is granted to use, distribute, or modify this source,
5
 * provided that this copyright notice remains intact.
6
 *
7
 * Main module of graphics server.
8
 */
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <signal.h>
12
#include <string.h>
13
 
14
#ifdef __PACIFIC__
15
#include <unixio.h>
16
#else
17
#include <errno.h>
18
#include <sys/types.h>
19
#endif
20
 
21
#ifdef DOS_TURBOC
22
#include <io.h>
23
#endif
24
 
25
#define MWINCLUDECOLORS
26
#include "serv.h"
27
#if UNIX | DOS_DJGPP
28
#include <unistd.h>
29
#if _MINIX
30
#include <sys/times.h>
31
#else
32
#include <sys/time.h>
33
#endif
34
#endif
35
 
36
#if DOS_DJGPP
37
typedef unsigned long DWORD;    /* FIXME why is this here?*/
38
#endif
39
 
40
#if ELKS
41
#include <linuxmt/posix_types.h>
42
#include <linuxmt/time.h>
43
#endif
44
 
45
#ifdef __ECOS
46
# include <pkgconf/system.h>
47
# include <pkgconf/microwindows.h>
48
# ifdef CYGPKG_NET
49
#  define NONETWORK 0
50
# else
51
#  error Not yet supported.
52
#  define NONETWORK 1
53
# endif
54
#endif
55
 
56
/*
57
 * External definitions defined here.
58
 */
59
GR_WINDOW_ID    cachewindowid;          /* cached window id */
60
GR_WINDOW_ID    cachepixmapid;         /* cached pixmap id */
61
GR_GC_ID        cachegcid;              /* cached graphics context id */
62
GR_WINDOW       *cachewp;               /* cached window pointer */
63
GR_GC           *cachegcp;              /* cached graphics context */
64
GR_PIXMAP       *cachepp;               /* cached pixmap */
65
GR_PIXMAP       *listpp;                /* List of all pixmaps */
66
GR_WINDOW       *listwp;                /* list of all windows */
67
GR_WINDOW       *rootwp;                /* root window pointer */
68
GR_GC           *listgcp;               /* list of all gc */
69
GR_REGION       *listregionp;           /* list of all regions */
70
GR_FONT         *listfontp;             /* list of all fonts */
71
GR_IMAGE        *listimagep;            /* list of all images */
72
GR_CURSOR       *listcursorp;           /* list of all cursors */
73
GR_CURSOR       *stdcursor;             /* root window cursor */
74
GR_GC           *curgcp;                /* currently enabled gc */
75
GR_WINDOW       *clipwp;                /* window clipping is set for */
76
GR_WINDOW       *focuswp;               /* focus window for keyboard */
77
GR_WINDOW       *mousewp;               /* window mouse is currently in */
78
GR_WINDOW       *grabbuttonwp;          /* window grabbed by button */
79
GR_CURSOR       *curcursor;             /* currently enabled cursor */
80
GR_COORD        cursorx;                /* current x position of cursor */
81
GR_COORD        cursory;                /* current y position of cursor */
82
int             curbuttons;             /* current state of buttons */
83
GR_CLIENT       *curclient;             /* client currently executing for */
84
GR_EVENT_LIST   *eventfree;             /* list of free events */
85
GR_BOOL         focusfixed;             /* TRUE if focus is fixed on a window */
86
PMWFONT         stdfont;                /* default font*/
87
int             escape_quits = 1;       /* terminate when pressing ESC */
88
char            *progname;              /* Name of this program.. */
89
 
90
int             current_fd;             /* the fd of the client talking to */
91
int             connectcount = 0;        /* number of connections to server */
92
GR_CLIENT       *root_client;           /* root entry of the client table */
93
GR_CLIENT       *current_client;        /* the client we are currently talking*/
94
char            *current_shm_cmds;
95
int             current_shm_cmds_size;
96
int             keyb_fd;                /* the keyboard file descriptor */
97
int             mouse_fd;               /* the mouse file descriptor */
98
char            *curfunc;               /* the name of the current server func*/
99
GR_TIMEOUT      screensaver_delay;      /* time before screensaver activates */
100
GR_BOOL         screensaver_active;     /* time before screensaver activates */
101
GR_SELECTIONOWNER selection_owner;      /* the selection owner and typelist */
102
GR_TIMEOUT      startTicks;             /* ms time server started*/
103
int             autoportrait = FALSE;   /* auto portrait mode switching*/
104
 
105
GR_TIMER_ID     cache_timer_id;         /* cached timer ID */
106
GR_TIMER        *cache_timer;           /* cached timer */
107
GR_TIMER        *list_timer;            /* list of all timers */
108
 
109
static int      persistent_mode = 0;
110
static int      portraitmode = MWPORTRAIT_NONE;
111
 
112
#if !NONETWORK
113
int             un_sock;                /* the server socket descriptor */
114
 
115
static void
116
usage(void)
117
{
118
        fprintf(stderr,"Usage: %s [-e] [-p] [-N] [-c <fontconfig-file> ...]\n",
119
                progname);
120
        exit(1);
121
}
122
 
123
/*
124
 * This is the main server loop which initialises the server, services
125
 * the clients, and shuts the server down when there are no more clients.
126
 */
127
#ifdef __ECOS
128
int
129
nanox_main(int argc, char *argv[])
130
#else
131
int
132
main(int argc, char *argv[])
133
#endif
134
{
135
        int t;
136
        int read_configfile(char *file);
137
 
138
        progname = argv[0];
139
 
140
        t = 1;
141
        while ( t < argc ) {
142
                if ( !strcmp("-e",argv[t])) {
143
                        escape_quits = 0;
144
                        t++;
145
                        continue;
146
                }
147
                if ( !strcmp("-p",argv[t]) ) {
148
                        persistent_mode = 1;
149
                        t++;
150
                        continue;
151
                }
152
                if ( !strcmp("-A",argv[t]) ) {
153
                        autoportrait = TRUE;
154
                        t++;
155
                        continue;
156
                }
157
                if ( !strcmp("-N",argv[t]) ) {
158
                        portraitmode = MWPORTRAIT_NONE;
159
                        t++;
160
                        continue;
161
                }
162
                if ( !strcmp("-L",argv[t]) ) {
163
                        portraitmode = MWPORTRAIT_LEFT;
164
                        t++;
165
                        continue;
166
                }
167
                if ( !strcmp("-R",argv[t]) ) {
168
                        portraitmode = MWPORTRAIT_RIGHT;
169
                        t++;
170
                        continue;
171
                }
172
                if ( !strcmp("-D",argv[t]) ) {
173
                        portraitmode = MWPORTRAIT_DOWN;
174
                        t++;
175
                        continue;
176
                }
177
#if FONTMAPPER
178
                if ( !strcmp("-c",argv[t]) ) {
179
                        if ( t+1 >= argc )
180
                                usage();
181
                        read_configfile(argv[t+1]);
182
                        t += 2;
183
                        continue;
184
                }
185
#endif
186
                usage();
187
        }
188
 
189
        /* Attempt to initialise the server*/
190
        if(GsInitialize() < 0)
191
                exit(1);
192
 
193
        while(1)
194
                GsSelect(0L);
195
        return 0;
196
}
197
#endif
198
 
199
void
200
GsAcceptClientFd(int i)
201
{
202
        GR_CLIENT *client, *cl;
203
 
204
        if(!(client = malloc(sizeof(GR_CLIENT)))) {
205
                close(i);
206
                return;
207
        }
208
 
209
        client->id = i;
210
        client->eventhead = NULL;
211
        client->eventtail = NULL;
212
        /*client->errorevent.type = GR_EVENT_TYPE_NONE;*/
213
        client->next = NULL;
214
        client->prev = NULL;
215
        client->waiting_for_event = FALSE;
216
        client->shm_cmds = 0;
217
 
218
        if(connectcount++ == 0)
219
                root_client = client;
220
        else {
221
                cl = root_client;
222
                        while(cl->next)
223
                                cl = cl->next;
224
                client->prev = cl;
225
                cl->next = client;
226
        }
227
}
228
 
229
/*
230
 * Open a connection from a new client to the server.
231
 * Returns -1 on failure.
232
 */
233
int
234
GrOpen(void)
235
{
236
#if NONETWORK
237
        escape_quits = 1;
238
 
239
        /* Client calls this routine once.  We
240
         * init everything here
241
         */
242
        if (connectcount <= 0) {
243
                if(GsInitialize() < 0)
244
                        return -1;
245
                GsAcceptClientFd(999);
246
                curclient = root_client;
247
        }
248
#endif
249
        return 1;
250
}
251
 
252
/*
253
 * Close the current connection to the server.
254
 */
255
void
256
GrClose(void)
257
{
258
        GsClose(current_fd);
259
}
260
 
261
/*
262
 * Drop a specific server connection.
263
 */
264
void
265
GsClose(int fd)
266
{
267
        GsDropClient(fd);
268
        if(!persistent_mode && connectcount == 0)
269
                GsTerminate();
270
}
271
 
272
#if NONETWORK
273
/* client/server GsDropClient is in srvnet.c*/
274
void
275
GsDropClient(int fd)
276
{
277
        --connectcount;
278
}
279
#endif
280
 
281
#if UNIX | DOS_DJGPP
282
#if NONETWORK && defined(HAVESELECT)
283
/*
284
 * Register the specified file descriptor to return an event
285
 * when input is ready.
286
 */
287
 
288
static int regfdmax = -1;
289
static fd_set regfdset;
290
 
291
void
292
GrRegisterInput(int fd)
293
{
294
        FD_SET(fd, &regfdset);
295
        if (fd > regfdmax) regfdmax = fd + 1;
296
}
297
 
298
void
299
GrUnregisterInput(int fd)
300
{
301
        int i, max;
302
 
303
        /* unregister all inputs if the FD is -1 */
304
        if (fd == -1) {
305
                FD_ZERO(&regfdset);
306
                regfdmax = -1;
307
                return;
308
        }
309
 
310
        FD_CLR(fd, &regfdset);
311
        /* recalculate the max file descriptor */
312
        for (i = 0, max = regfdmax, regfdmax = -1; i < max; i++)
313
                if (FD_ISSET(i, &regfdset))
314
                        regfdmax = i + 1;
315
}
316
 
317
#endif /* NONETWORK && HAVESELECT */
318
#endif /* UNIX | DOS_DJGPP*/
319
 
320
/*
321
 * This function suspends execution of the program for the specified
322
 * number of milliseconds.
323
 */
324
void
325
GrDelay(GR_TIMEOUT msecs)
326
{
327
#if UNIX
328
        struct timeval timeval;
329
 
330
        timeval.tv_sec = msecs / 1000;
331
        timeval.tv_usec = msecs % 1000;
332
        select(0, NULL, NULL, NULL, &timeval);
333
#endif
334
}
335
 
336
#if NONETWORK
337
void
338
GrFlush(void)
339
{
340
}
341
 
342
void
343
GrMainLoop(GR_FNCALLBACKEVENT fncb)
344
{
345
        GR_EVENT event;
346
 
347
        for(;;) {
348
                GrGetNextEvent(&event);
349
                fncb(&event);
350
        }
351
}
352
 
353
void
354
GrReqShmCmds(long shmsize)
355
{
356
        /* no action required, no client/server*/
357
}
358
#endif
359
 
360
 
361
#if VXWORKS
362
 
363
#define POLLTIME        100   /* polling sleep interval (in msec) */
364
#define MAX_MOUSEEVENTS 10    /* max number of mouse event to get in 1 select */
365
#define MAX_KEYBDEVENTS 10    /* max number of mouse event to get in 1 select */
366
 
367
extern void GdSleep(int dwMilliseconds);
368
 
369
void
370
GsSelect(GR_TIMEOUT timeout)
371
{
372
        int mouseevents = 0;
373
        int keybdevents = 0;
374
        GR_TIMEOUT waittime = 0;
375
        GR_EVENT_GENERAL *gp;
376
 
377
 
378
        /* input gathering loop */
379
        while (1)
380
        {
381
 
382
                /* perform pre-select duties, if any */
383
                if(scrdev.PreSelect)
384
                {
385
                        scrdev.PreSelect(&scrdev);
386
                }
387
 
388
 
389
                /* If mouse data present, service it */
390
                while (mousedev.Poll() > 0)
391
                {
392
                        GsCheckMouseEvent();
393
                        if (mouseevents++ > MAX_MOUSEEVENTS)
394
                        {
395
                                /* don't handle too many events at one shot */
396
                                break;
397
                        }
398
                }
399
 
400
 
401
                /* If keyboard data present, service it */
402
                while (kbddev.Poll() > 0)
403
                {
404
                        GsCheckKeyboardEvent();
405
                        if (keybdevents++ > MAX_KEYBDEVENTS)
406
                        {
407
                                /* don't handle too many events at one shot */
408
                                break;
409
                        }
410
                }
411
 
412
 
413
                /* did we process any input yet? */
414
                if ((mouseevents > 0) || (keybdevents > 0))
415
                {
416
                        /* yep -- return without sleeping */
417
                        return;
418
                }
419
 
420
 
421
                /* give up time-slice & sleep for a bit */
422
                GdSleep(POLLTIME);
423
                waittime += POLLTIME;
424
 
425
 
426
                /* have we timed out? */
427
                if (waittime >= timeout)
428
                {
429
                        /* special case: polling when timeout == 0 -- don't send timeout event */
430
                        if (timeout != 0)
431
                        {
432
                                /* Timeout has occured.
433
                                ** Currently return a timeout event regardless of whether client
434
                                **   has selected for it.
435
                                */
436
                                if ((gp = (GR_EVENT_GENERAL *)GsAllocEvent(curclient)) != NULL)
437
                                {
438
                                        gp->type = GR_EVENT_TYPE_TIMEOUT;
439
                                }
440
                        }
441
                        return;
442
                }
443
        }
444
 
445
}
446
 
447
#elif MSDOS | _MINIX
448
 
449
void
450
GsSelect(GR_TIMEOUT timeout)
451
{
452
        /* If mouse data present, service it*/
453
        if(mousedev.Poll())
454
                while(GsCheckMouseEvent())
455
                        continue;
456
 
457
        /* If keyboard data present, service it*/
458
        if(kbddev.Poll())
459
                while(GsCheckKeyboardEvent())
460
                        continue;
461
 
462
}
463
 
464
#elif defined(__ECOS) && defined(CYGPKG_HAL_I386_PCMB)
465
 
466
// For eCos on PC, use polling for the mouse and keyboard. Also
467
// use select() with a short timeout for communication.
468
//
469
// This needs fixing up later.
470
void
471
GsSelect(GR_TIMEOUT timeout)
472
{
473
        fd_set  rfds;
474
    int     setsize = 0;
475
        struct  timeval tout;
476
    int     real_timeout;
477
    int     e;
478
 
479
        /* If mouse data present, service it*/
480
        if(mousedev.Poll())
481
                while(GsCheckMouseEvent())
482
                        continue;
483
 
484
        /* If keyboard data present, service it*/
485
        if(kbddev.Poll())
486
                while(GsCheckKeyboardEvent())
487
                        continue;
488
 
489
    FD_ZERO(&rfds);
490
        /* perform pre-select duties, if any*/
491
        if(rootwp->psd->PreSelect)
492
                rootwp->psd->PreSelect(rootwp->psd);
493
 
494
        /* handle client socket connections*/
495
        FD_SET(un_sock, &rfds);
496
        if (un_sock > setsize) setsize = un_sock;
497
        curclient = root_client;
498
        while(curclient) {
499
                if(curclient->waiting_for_event && curclient->eventhead) {
500
                        curclient->waiting_for_event = FALSE;
501
                        GrGetNextEventWrapperFinish(curclient->id);
502
                        return;
503
                }
504
                FD_SET(curclient->id, &rfds);
505
                if(curclient->id > setsize) setsize = curclient->id;
506
                curclient = curclient->next;
507
        }
508
 
509
        /* Set up the timeout for the main select(): */
510
        if(GdGetNextTimeout(&tout, timeout) == TRUE) {
511
        if ((tout.tv_sec > 0) || (tout.tv_usec > 20000)) {
512
            tout.tv_sec  = 0;
513
            tout.tv_usec = 20000;
514
            real_timeout = 0;
515
        } else {
516
            real_timeout = 1;
517
        }
518
    } else {
519
        tout.tv_sec  = 0;
520
        tout.tv_usec = 20000;
521
        real_timeout = 0;
522
    }
523
 
524
        /* Wait for some input on any of the fds in the set or a timeout: */
525
        if((e = select(setsize+1, &rfds, NULL, NULL, &tout)) > 0) {
526
                /* If a client is trying to connect, accept it: */
527
                if(FD_ISSET(un_sock, &rfds))
528
                        GsAcceptClient();
529
 
530
                /* If a client is sending us a command, handle it: */
531
                curclient = root_client;
532
                while(curclient) {
533
                        GR_CLIENT *curclient_next;
534
 
535
                        /* curclient may be freed in GsDropClient*/
536
                        curclient_next = curclient->next;
537
                        if(FD_ISSET(curclient->id, &rfds))
538
                                GsHandleClient(curclient->id);
539
                        curclient = curclient_next;
540
                }
541
        }
542
        else if (e == 0) {
543
        if (real_timeout) {
544
            GdTimeout();
545
        }
546
        } else
547
                if(errno != EINTR)
548
                        EPRINTF("Select() call in main failed\n");
549
}
550
 
551
#elif UNIX && defined(HAVESELECT)
552
 
553
void
554
GsSelect(GR_TIMEOUT timeout)
555
{
556
        fd_set  rfds;
557
        int     e;
558
        int     setsize = 0;
559
        struct timeval tout, *to;
560
#if NONETWORK
561
        int     fd;
562
#endif
563
 
564
        /* perform pre-select duties, if any*/
565
        if(rootwp->psd->PreSelect)
566
                rootwp->psd->PreSelect(rootwp->psd);
567
 
568
        /* Set up the FDs for use in the main select(): */
569
        FD_ZERO(&rfds);
570
        if(mouse_fd >= 0) {
571
                FD_SET(mouse_fd, &rfds);
572
                if (mouse_fd > setsize)
573
                        setsize = mouse_fd;
574
        }
575
        if(keyb_fd >= 0) {
576
                FD_SET(keyb_fd, &rfds);
577
                if (keyb_fd > setsize)
578
                        setsize = keyb_fd;
579
        }
580
#if NONETWORK
581
        /* handle registered input file descriptors*/
582
        for (fd = 0; fd < regfdmax; fd++) {
583
                if (!FD_ISSET(fd, &regfdset))
584
                        continue;
585
 
586
                FD_SET(fd, &rfds);
587
                if (fd > setsize) setsize = fd;
588
        }
589
#else /* not NONETWORK */
590
        /* handle client socket connections*/
591
        FD_SET(un_sock, &rfds);
592
        if (un_sock > setsize) setsize = un_sock;
593
        curclient = root_client;
594
        while(curclient) {
595
                if(curclient->waiting_for_event && curclient->eventhead) {
596
                        curclient->waiting_for_event = FALSE;
597
                        GrGetNextEventWrapperFinish(curclient->id);
598
                        return;
599
                }
600
                FD_SET(curclient->id, &rfds);
601
                if(curclient->id > setsize) setsize = curclient->id;
602
                curclient = curclient->next;
603
        }
604
#endif /* NONETWORK */
605
        /* Set up the timeout for the main select(): */
606
        if(GdGetNextTimeout(&tout, timeout) == TRUE)
607
                to = &tout;
608
        else to = NULL;
609
 
610
        /* Wait for some input on any of the fds in the set or a timeout: */
611
        if((e = select(setsize+1, &rfds, NULL, NULL, to)) > 0) {
612
                /* If data is present on the mouse fd, service it: */
613
                if(mouse_fd >= 0 && FD_ISSET(mouse_fd, &rfds))
614
                        while(GsCheckMouseEvent())
615
                                continue;
616
 
617
                /* If data is present on the keyboard fd, service it: */
618
                if(keyb_fd >= 0 && FD_ISSET(keyb_fd, &rfds))
619
                        while(GsCheckKeyboardEvent())
620
                                continue;
621
 
622
#if NONETWORK
623
                /* check for input on registered file descriptors */
624
                for (fd = 0; fd < regfdmax; fd++) {
625
                        GR_EVENT_FDINPUT *      gp;
626
 
627
                        if (!FD_ISSET(fd, &regfdset)  ||  !FD_ISSET(fd, &rfds))
628
                                continue;
629
 
630
                        gp =(GR_EVENT_FDINPUT *)GsAllocEvent(curclient);
631
                        if(gp) {
632
                                gp->type = GR_EVENT_TYPE_FDINPUT;
633
                                gp->fd = fd;
634
                        }
635
                }
636
#else /* not NONETWORK */
637
 
638
                /* If a client is trying to connect, accept it: */
639
                if(FD_ISSET(un_sock, &rfds))
640
                        GsAcceptClient();
641
 
642
                /* If a client is sending us a command, handle it: */
643
                curclient = root_client;
644
                while(curclient) {
645
                        GR_CLIENT *curclient_next;
646
 
647
                        /* curclient may be freed in GsDropClient*/
648
                        curclient_next = curclient->next;
649
                        if(FD_ISSET(curclient->id, &rfds))
650
                                GsHandleClient(curclient->id);
651
                        curclient = curclient_next;
652
                }
653
#endif /* NONETWORK */
654
        }
655
        else if (e == 0) {
656
#if NONETWORK
657
                /*
658
                 * Timeout has occured.  Currently return
659
                 * a timeout event regardless of whether
660
                 * client has selected for it.
661
                 */
662
                if(GdTimeout() == TRUE) {
663
                        GR_EVENT_GENERAL *      gp;
664
                        gp = (GR_EVENT_GENERAL *)GsAllocEvent(curclient);
665
                        if(gp)
666
                                gp->type = GR_EVENT_TYPE_TIMEOUT;
667
                }
668
#else /* not NONETWORK */
669
                GdTimeout();
670
#endif /* NONETWORK */
671
        } else
672
                if(errno != EINTR)
673
                        EPRINTF("Select() call in main failed\n");
674
}
675
#endif /* UNIX && defined(HAVESELECT)*/
676
 
677
#if VTSWITCH
678
static void
679
CheckVtChange(void *arg)
680
{
681
        if(MwCheckVtChange())
682
                GsRedrawScreen();
683
        GdAddTimer(50, CheckVtChange, NULL);
684
}
685
#endif
686
 
687
/*
688
 * Initialize the graphics and mouse devices at startup.
689
 * Returns nonzero with a message printed if the initialization failed.
690
 */
691
int
692
GsInitialize(void)
693
{
694
        GR_WINDOW       *wp;            /* root window */
695
        PSD             psd;
696
        GR_CURSOR_ID    cid;
697
        static MWIMAGEBITS cursorbits[16] = {
698
              0xe000, 0x9800, 0x8600, 0x4180,
699
              0x4060, 0x2018, 0x2004, 0x107c,
700
              0x1020, 0x0910, 0x0988, 0x0544,
701
              0x0522, 0x0211, 0x000a, 0x0004
702
        };
703
        static MWIMAGEBITS cursormask[16] = {
704
              0xe000, 0xf800, 0xfe00, 0x7f80,
705
              0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc,
706
              0x1fe0, 0x0ff0, 0x0ff8, 0x077c,
707
              0x073e, 0x021f, 0x000e, 0x0004
708
        };
709
 
710
        wp = (GR_WINDOW *) malloc(sizeof(GR_WINDOW));
711
        if (wp == NULL) {
712
                EPRINTF("Cannot allocate root window\n");
713
                return -1;
714
        }
715
 
716
        startTicks = GsGetTickCount();
717
 
718
        /* catch terminate signal to restore tty state*/
719
        signal(SIGTERM, (void *)GsTerminate);
720
 
721
        screensaver_delay = 0;
722
        screensaver_active = GR_FALSE;
723
 
724
        selection_owner.wid = 0;
725
        selection_owner.typelist = NULL;
726
 
727
#if !NONETWORK
728
        /* ignore pipe signal, sent when clients exit*/
729
        signal(SIGPIPE, SIG_IGN);
730
        signal(SIGHUP, SIG_IGN);
731
 
732
        if (GsOpenSocket() < 0) {
733
                EPRINTF("Cannot bind to named socket\n");
734
                free(wp);
735
                return -1;
736
        }
737
#endif
738
 
739
        if ((keyb_fd = GdOpenKeyboard()) == -1) {
740
                EPRINTF("Cannot initialise keyboard\n");
741
                /*GsCloseSocket();*/
742
                free(wp);
743
                return -1;
744
        }
745
 
746
        if ((psd = GdOpenScreen()) == NULL) {
747
                EPRINTF("Cannot initialise screen\n");
748
                /*GsCloseSocket();*/
749
                GdCloseKeyboard();
750
                free(wp);
751
                return -1;
752
        }
753
        GdSetPortraitMode(psd, portraitmode);
754
 
755
        if ((mouse_fd = GdOpenMouse()) == -1) {
756
                EPRINTF("Cannot initialise mouse\n");
757
                /*GsCloseSocket();*/
758
                GdCloseScreen(psd);
759
                GdCloseKeyboard();
760
                free(wp);
761
                return -1;
762
        }
763
 
764
        /*
765
         * Create std font.
766
         */
767
#if (HAVE_BIG5_SUPPORT | HAVE_GB2312_SUPPORT)
768
        /* system fixed font looks better when mixed with chinese fonts*/
769
        stdfont = GdCreateFont(psd, MWFONT_SYSTEM_FIXED, 0, NULL);
770
#else
771
        stdfont = GdCreateFont(psd, MWFONT_SYSTEM_VAR, 0, NULL);
772
#endif
773
 
774
        /*
775
         * Initialize the root window.
776
         */
777
        wp->psd = psd;
778
        wp->id = GR_ROOT_WINDOW_ID;
779
        wp->parent = NULL;              /* changed: was = NULL*/
780
        wp->owner = NULL;
781
        wp->children = NULL;
782
        wp->siblings = NULL;
783
        wp->next = NULL;
784
        wp->x = 0;
785
        wp->y = 0;
786
        wp->width = psd->xvirtres;
787
        wp->height = psd->yvirtres;
788
        wp->bordersize = 0;
789
        wp->background = BLACK;
790
        wp->bordercolor = BLACK;
791
        wp->nopropmask = 0;
792
        wp->bgpixmap = NULL;
793
        wp->bgpixmapflags = GR_BACKGROUND_TILE;
794
        wp->eventclients = NULL;
795
        wp->cursorid = 0;
796
        wp->mapped = GR_TRUE;
797
        wp->unmapcount = 0;
798
        wp->output = GR_TRUE;
799
        wp->props = 0;
800
        wp->title = NULL;
801
 
802
        listpp = NULL;
803
        listwp = wp;
804
        rootwp = wp;
805
        focuswp = wp;
806
        mousewp = wp;
807
        focusfixed = GR_FALSE;
808
 
809
        /*
810
         * Initialize and position the default cursor.
811
         */
812
        curcursor = NULL;
813
        cursorx = -1;
814
        cursory = -1;
815
        GdShowCursor(psd);
816
        GrMoveCursor(psd->xvirtres / 2, psd->yvirtres / 2);
817
        cid = GrNewCursor(16, 16, 0, 0, WHITE, BLACK, cursorbits, cursormask);
818
        GrSetWindowCursor(GR_ROOT_WINDOW_ID, cid);
819
        stdcursor = GsFindCursor(cid);
820
 
821
#if VTSWITCH
822
        MwInitVt();
823
        /* Check for VT change every 50 ms: */
824
        GdAddTimer(50, CheckVtChange, NULL);
825
#endif
826
        psd->FillRect(psd, 0, 0, psd->xvirtres-1, psd->yvirtres-1,
827
                GdFindColor(BLACK));
828
 
829
        /*
830
         * Tell the mouse driver some things.
831
         */
832
        curbuttons = 0;
833
        GdRestrictMouse(0, 0, psd->xvirtres - 1, psd->yvirtres - 1);
834
        GdMoveMouse(psd->xvirtres / 2, psd->yvirtres / 2);
835
 
836
        /* Force root window screen paint*/
837
        GsRedrawScreen();
838
 
839
        /*
840
         * Force the cursor to appear on the screen at startup.
841
         * (not required with above GsRedrawScreen)
842
        GdHideCursor(psd);
843
        GdShowCursor(psd);
844
         */
845
 
846
        /*
847
         * All done.
848
         */
849
        connectcount = 0;
850
        return 0;
851
}
852
 
853
/*
854
 * Here to close down the server.
855
 */
856
void
857
GsTerminate(void)
858
{
859
#if !NONETWORK
860
        GsCloseSocket();
861
#endif
862
        GdCloseScreen(rootwp->psd);
863
        GdCloseMouse();
864
        GdCloseKeyboard();
865
#if VTSWITCH
866
        MwRedrawVt(mwvterm);
867
#endif
868
        exit(0);
869
}
870
 
871
/*
872
 * Return # milliseconds elapsed since start of Microwindows
873
 * Granularity is 25 msec
874
 */
875
GR_TIMEOUT
876
GsGetTickCount(void)
877
{
878
#if MSDOS
879
#include <time.h>
880
        return (DWORD)(clock() * 1000 / CLOCKS_PER_SEC);
881
#else
882
#if _MINIX
883
        struct tms      t;
884
 
885
        return (DWORD)times(&t) * 16;
886
#else
887
#if UNIX
888
        struct timeval t;
889
 
890
        gettimeofday(&t, NULL);
891
        return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - startTicks;
892
#else
893
        return 0L;
894
#endif
895
#endif
896
#endif
897
}
898
 
899
void
900
GrBell(void)
901
{
902
        write(2, "\7", 1);
903
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.