summaryrefslogtreecommitdiff
path: root/Source/SaWMan/samples/testman.c
blob: d2af297b9ab4dcd2e676d236805d7f1bbc0ef6c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/*
   (c) Copyright 2006-2007  directfb.org

   All rights reserved.

   Written by Denis Oliver Kropp <dok@directfb.org>.

   This file is subject to the terms and conditions of the MIT License:
  
   Permission is hereby granted, free of charge, to any person
   obtaining a copy of this software and associated documentation
   files (the "Software"), to deal in the Software without restriction,
   including without limitation the rights to use, copy, modify, merge,
   publish, distribute, sublicense, and/or sell copies of the Software,
   and to permit persons to whom the Software is furnished to do so,
   subject to the following conditions:
  
   The above copyright notice and this permission notice shall be
   included in all copies or substantial portions of the Software.
  
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <config.h>


#include <unistd.h>
#include <string.h>

#include <sys/types.h>
#include <sys/wait.h>

#include <directfb.h>
#include <directfb_util.h>

#include <direct/clock.h>
#include <direct/messages.h>

#include <sawman.h>

#define MAX_WINDOWS 4
#define MAX_LAYOUTS 4

#define CHECK(x)                                  \
     do {                                         \
          DFBResult ret = (x);                    \
          if (ret != DFB_OK) {                    \
               DirectFBError(#x,ret);             \
               goto out;                          \
          }                                       \
     } while (0)


typedef struct __TestMan_TestManager    TestManager;
typedef struct __TestMan_Layout         Layout;
typedef struct __TestMan_Application    Application;

/**********************************************************************************************************************/

struct __TestMan_TestManager {
     int                magic;

     IDirectFB         *dfb;
     ISaWMan           *saw;
     ISaWManManager    *manager;

     SaWManScalingMode  scaling_mode;

     SaWManWindowHandle   windows[MAX_WINDOWS];
     int                  num_windows;
     SaWManWindowHandle   focus_window;

     const Layout      *layouts[MAX_LAYOUTS];
     int                num_layouts;
     int                current_layout;

     DirectLink        *applications;
};

struct __TestMan_Layout {
     void *data;

     void (*Relayout)    ( TestManager  *tm,
                           void         *layout_data );

     void (*AddWindow)   ( TestManager        *tm,
                           void               *layout_data,
                           SaWManWindowHandle  window );

     void (*RemoveWindow)( TestManager        *tm,
                           void               *layout_data,
                           SaWManWindowHandle  window,
                           int                 index );
};

struct __TestMan_Application {
     DirectLink         link;

     int                magic;

     const char        *name;
     const char        *program;
     const char        *args;

     bool               started;

     long long          start_time;
     pid_t              pid;
     SaWManProcess     *process;
};

/**********************************************************************************************************************/

static void
AddApplication( TestManager *tm,
                const char  *name,
                const char  *program,
                const char  *args )
{
     Application *app;

     D_MAGIC_ASSERT( tm, TestManager );
     D_ASSERT( name != NULL );
     D_ASSERT( program != NULL );

     app = D_CALLOC( 1, sizeof(Application) );
     if (!app) {
          D_OOM();
          return;
     }

     app->name    = name;
     app->program = program;
     app->args    = args;

     direct_list_append( &tm->applications, &app->link );

     D_MAGIC_SET( app, Application );
}

static Application *
LookupApplication( TestManager *tm,
                   const char  *name )
{
     Application *app;

     D_MAGIC_ASSERT( tm, TestManager );
     D_ASSERT( name != NULL );

     direct_list_foreach (app, tm->applications) {
          D_MAGIC_ASSERT( app, Application );

          if (!strcmp( app->name, name ))
               return app;
     }

     return NULL;
}

static Application *
LookupApplicationByPID( TestManager *tm,
                        pid_t        pid )
{
     Application *app;

     D_MAGIC_ASSERT( tm, TestManager );

     direct_list_foreach (app, tm->applications) {
          D_MAGIC_ASSERT( app, Application );

          if (app->pid == pid)
               return app;
     }

     return NULL;
}

/**********************************************************************************************************************/

static void
MosaicRelayout( TestManager *tm,
                void        *layout_data )
{
     int             i;
     int             hcenter;
     int             vcenter;
     ISaWManManager *manager;
     DFBRectangle    bounds[4];
     DFBDimension    size;

     D_MAGIC_ASSERT( tm, TestManager );

     if (!tm->num_windows)
          return;

     manager = tm->manager;
     D_ASSERT( manager != NULL );

     manager->Lock( manager );

     manager->GetSize( manager, DWSC_MIDDLE, &size );

     hcenter = (size.w / 2) & ~1;
     vcenter = size.h / 2;

     switch (tm->num_windows) {
          case 0:
          case 1:
               bounds[0].x = 0;
               bounds[0].y = 0;
               bounds[0].w = size.w;
               bounds[0].h = size.h;

               break;

          case 2:
               bounds[0].x = 0;
               bounds[0].y = 0;
               bounds[0].w = hcenter;
               bounds[0].h = size.h;

               bounds[1].x = hcenter;
               bounds[1].y = 0;
               bounds[1].w = size.w - hcenter;
               bounds[1].h = size.h;

               break;

          case 3:
               bounds[0].x = 0;
               bounds[0].y = 0;
               bounds[0].w = hcenter;
               bounds[0].h = vcenter;

               bounds[1].x = 0;
               bounds[1].y = vcenter;
               bounds[1].w = hcenter;
               bounds[1].h = size.h - vcenter;

               bounds[2].x = hcenter;
               bounds[2].y = 0;
               bounds[2].w = size.w - hcenter;
               bounds[2].h = size.h;

               break;

          case 4:
               bounds[0].x = 0;
               bounds[0].y = 0;
               bounds[0].w = hcenter;
               bounds[0].h = vcenter;

               bounds[1].x = 0;
               bounds[1].y = vcenter;
               bounds[1].w = hcenter;
               bounds[1].h = size.h - vcenter;

               bounds[2].x = hcenter;
               bounds[2].y = 0;
               bounds[2].w = size.w - hcenter;
               bounds[2].h = vcenter;

               bounds[3].x = hcenter;
               bounds[3].y = vcenter;
               bounds[3].w = size.w - hcenter;
               bounds[3].h = size.h - vcenter;

               break;

          default:
               D_BUG( "invalid number of windows (%d)", tm->num_windows );
               break;
     }

     for (i=0; i<tm->num_windows; i++) {
          SaWManWindowHandle        window = tm->windows[i];
          SaWManWindowConfig        config;
          SaWManWindowConfigFlags   flags;
          
          flags = SWMCF_POSITION | SWMCF_SIZE;
          config.bounds = bounds[i];
          manager->SetWindowConfig( manager, window, flags, &config );
     }

     manager->QueueUpdate( manager, DWSC_MIDDLE, NULL );

     manager->Unlock( manager );
}

static void
MosaicAddWindow( TestManager        *tm,
                 void               *layout_data,
                 SaWManWindowHandle  window )
{
     ISaWManManager *manager;

     D_MAGIC_ASSERT( tm, TestManager );

     manager = tm->manager;
     D_ASSERT( manager != NULL );

     manager->Lock( manager );

     tm->windows[tm->num_windows++] = window;

     manager->InsertWindow( manager, window, SAWMAN_WINDOW_NONE, SWMWR_TOP );

     MosaicRelayout( tm, layout_data );

     manager->Unlock( manager );
}

static void
MosaicRemoveWindow( TestManager        *tm,
                    void               *layout_data,
                    SaWManWindowHandle  window,
                    int                 index )
{
     ISaWManManager *manager;

     D_MAGIC_ASSERT( tm, TestManager );

     manager = tm->manager;
     D_ASSERT( manager != NULL );

     manager->Lock( manager );

     /* Remove window from layout. */
     manager->RemoveWindow( manager, window );

     MosaicRelayout( tm, layout_data );

     manager->Unlock( manager );
}

static const Layout mosaic_layout = {
     data:          NULL,
     Relayout:      MosaicRelayout,
     AddWindow:     MosaicAddWindow,
     RemoveWindow:  MosaicRemoveWindow
};

/**********************************************************************************************************************/

static DFBResult
LayoutWindowAdd( TestManager        *tm,
                 SaWManWindowHandle  window )
{
     const Layout *layout;

     D_MAGIC_ASSERT( tm, TestManager );

     D_ASSERT( tm->current_layout >= 0 );
     D_ASSERT( tm->current_layout < tm->num_layouts );

     layout = tm->layouts[tm->current_layout];

     D_ASSERT( layout != NULL );
     D_ASSERT( layout->AddWindow != NULL );

     if (tm->num_windows == MAX_WINDOWS) {
          D_WARN( "maximum number (%d) of managed windows exceeded", MAX_WINDOWS );
          return DFB_LIMITEXCEEDED;
     }

     /* Set some default borders. */
     //window->border_normal     = 2;
     //window->border_fullscreen = 4;

     /* Call the layout implementation. */
     layout->AddWindow( tm, layout->data, window );

     return DFB_OK;
}

static DFBResult
LayoutWindowRemove( TestManager        *tm,
                    SaWManWindowHandle  window )
{
     int           i;
     const Layout *layout;

     D_MAGIC_ASSERT( tm, TestManager );

     D_ASSERT( tm->current_layout >= 0 );
     D_ASSERT( tm->current_layout < tm->num_layouts );

     layout = tm->layouts[tm->current_layout];

     D_ASSERT( layout != NULL );
     D_ASSERT( layout->RemoveWindow != NULL );

     for (i=0; i<tm->num_windows; i++) {
          if (tm->windows[i] == window)
               break;
     }

     if (i == MAX_WINDOWS) {
          D_BUG( "could not find window %lx", window );
          return DFB_BUG;
     }

     /* Remove window from our own list of managed windows. */
     for (; i<tm->num_windows-1; i++)
          tm->windows[i] = tm->windows[i+1];

     tm->windows[i] = SAWMAN_WINDOW_NONE;

     tm->num_windows--;

     /* Call the layout implementation. */
     layout->RemoveWindow( tm, layout->data, window, i );

     return DFB_OK;
}

/**********************************************************************************************************************/

static DirectResult
start_request( void       *context,
               const char *name,
               pid_t      *ret_pid )
{
     TestManager *tm = context;
     Application *app;
     pid_t        pid;
     const char  *args[3];

     D_INFO( "SaWMan/TestMan: Start request for '%s'!\n", name );

     D_MAGIC_ASSERT( tm, TestManager );
     D_ASSERT( name != NULL );
     D_ASSERT( ret_pid != NULL );

     app = LookupApplication( tm, name );
     if (!app)
          return DFB_ITEMNOTFOUND;

     if (app->started && !waitpid( app->pid, NULL, WNOHANG )) {
          D_DEBUG( "Already running '%s' (%d)!", name, app->pid );
          return DFB_BUSY;
     }

     app->started = true;

     app->start_time = direct_clock_get_millis();

     pid = vfork();

     switch (pid) {
          case -1:
               perror("vfork");
               return DFB_FAILURE;

          case 0:
               setsid();

               args[0] = app->program;
               args[1] = app->args;
               args[2] = NULL;

               execvp( app->program, (char**) args );
               perror("execvp");
               _exit(0);

          default:
               app->pid = pid;
               break;
     }

     *ret_pid = pid;

     return DFB_OK;
}

static DirectResult
stop_request( void     *context,
              pid_t     pid,
              FusionID  caller )
{
     TestManager *tm = context;
     Application *app;

     D_INFO( "SaWMan/TestMan: Stop request from Fusion ID 0x%lx for pid %d!\n", caller, pid );

     D_MAGIC_ASSERT( tm, TestManager );

     app = LookupApplicationByPID( tm, pid );
     if (!app)
          return DFB_ITEMNOTFOUND;

     /* Already died before attaching? */
     if (waitpid( app->pid, NULL, WNOHANG )) {
          app->started = false;
          app->pid     = 0;

          return DFB_OK;
     }

     /* Not attached yet? */
     if (!app->process) {
          D_ERROR( "Application with pid %d did not attach yet!\n", app->pid );
          return DFB_NOCONTEXT;
     }

     /* FIXME: avoid signals */
     kill( app->pid, 9 );

     return DFB_OK;
}

static DirectResult
process_added( void          *context,
               SaWManProcess *process )
{
     TestManager *tm = context;
     Application *app;

     D_INFO( "SaWMan/TestMan: Process added (%d) [%lu]!\n", process->pid, process->fusion_id );

     D_MAGIC_ASSERT( tm, TestManager );

     app = LookupApplicationByPID( tm, process->pid );
     if (!app)
          return DFB_ITEMNOTFOUND;

     if (app->process) {
          D_BUG( "Already attached '%s' (%d)!", app->name, app->pid );
          return DFB_BUG;
     }

     app->process = process;

     return DFB_OK;
}

static DirectResult
process_removed( void          *context,
                 SaWManProcess *process )
{
     TestManager *tm = context;
     Application *app;

     D_INFO( "SaWMan/TestMan: Process removed (%d) [%lu]!\n", process->pid, process->fusion_id );

     D_MAGIC_ASSERT( tm, TestManager );

     app = LookupApplicationByPID( tm, process->pid );
     if (!app)
          return DFB_ITEMNOTFOUND;

     if (app->process != process) {
          D_BUG( "Process mismatch %p != %p of '%s' (%d)!", app->process, process, app->name, app->pid );
          return DFB_BUG;
     }

     if (waitpid( app->pid, NULL, 0 ) < 0)
          perror("waitpid");

     app->process = NULL;
     app->started = false;
     app->pid     = 0;

     return DFB_OK;
}

static DirectResult
input_filter( void          *context,
              DFBInputEvent *event )
{
     int             i;
     TestManager    *tm = context;
     ISaWManManager *manager;

//     D_INFO( "SaWMan/TestMan: Input filter (%x)!\n", event->type );

     D_MAGIC_ASSERT( tm, TestManager );

     manager = tm->manager;

     D_ASSERT( manager != NULL );

     manager->Lock( manager );

     switch (event->type) {
          case DIET_KEYPRESS:
               switch (event->key_symbol) {
                    case DIKS_F9:
                         if (tm->num_windows > 1) {
                              for (i=0; i<tm->num_windows; i++) {
                                   SaWManWindowHandle window = tm->windows[i];

                                   if (window == tm->focus_window) {
                                        window = tm->windows[(i+1) % tm->num_windows];

                                        manager->SwitchFocus( manager, window );

                                        break;
                                   }
                              }
                         }
                         manager->Unlock( manager );
                         return DFB_BUSY;

                    case DIKS_F10:
                         if (tm->num_layouts > 1) {
                              const Layout *layout;

                              if (++tm->current_layout == tm->num_layouts)
                                   tm->current_layout = 0;

                              layout = tm->layouts[tm->current_layout];

                              D_ASSERT( layout != NULL );
                              D_ASSERT( layout->Relayout != NULL );

                              layout->Relayout( tm, layout->data );
                         }
                         manager->Unlock( manager );
                         return DFB_BUSY;

                    case DIKS_F11:
                         tm->scaling_mode = (tm->scaling_mode == SWMSM_SMOOTH_SW) ? SWMSM_STANDARD : SWMSM_SMOOTH_SW;
                         manager->SetScalingMode( manager, tm->scaling_mode );
                         manager->Unlock( manager );
                         return DFB_BUSY;

                    default:
                         break;
               }

          case DIET_KEYRELEASE:
               switch (event->key_symbol) {
                    case DIKS_F9:
                    case DIKS_F10:
                    case DIKS_F11:
                         manager->Unlock( manager );
                         return DFB_BUSY;

                    default:
                         break;
               }

          default:
               break;
     }

     manager->Unlock( manager );
     return DFB_OK;
}


static DirectResult
window_preconfig( void               *context,
                  SaWManWindowConfig *config )
{
     D_INFO( "SaWMan/TestMan: Window preconfig (%d,%d-%dx%d)!\n",
             DFB_RECTANGLE_VALS( &config->bounds ) );

     return DFB_OK;
}

static DirectResult
window_added( void               *context,
              SaWManWindowInfo   *info )
{
     DFBResult    ret;
     TestManager *tm = context;

     D_MAGIC_ASSERT( tm, TestManager );

     D_INFO( "SaWMan/TestMan: Window added (%d,%d-%dx%d)!\n",
             DFB_RECTANGLE_VALS( &info->config.bounds ) );

     if (info->caps & DWCAPS_NODECORATION)
          return DFB_NOIMPL;  /* to let sawman insert the window */

     /* Already showing window? (reattaching) */
     if (info->config.opacity) {
          /* Activate scaling. */
          info->config.options |= DWOP_SCALE;

          ret = LayoutWindowAdd( tm, info->handle );
          if (ret)
               return ret;
     }

     return DFB_OK;
}

static DirectResult
window_removed( void               *context,
                SaWManWindowInfo   *info )
{
     D_INFO( "SaWMan/TestMan: Window removed (%d,%d-%dx%d)!\n",
             DFB_RECTANGLE_VALS( &info->config.bounds ) );

     return DFB_OK;
}

static DirectResult
window_reconfig( void                 *context,
                 SaWManWindowReconfig *reconfig )
{
     DFBResult           ret;
     TestManager        *tm = context;
     SaWManWindowConfig *current;
     SaWManWindowConfig *request;

     D_MAGIC_ASSERT( tm, TestManager );

     if (reconfig->caps & DWCAPS_NODECORATION)
          return DFB_OK;

     current = &reconfig->current;
     request = &reconfig->request;

     if (reconfig->flags & SWMCF_POSITION) {
          D_INFO( "SaWMan/TestMan: Window config - ignoring position (%d,%d)!\n", request->bounds.x, request->bounds.y );
          reconfig->flags &= ~SWMCF_POSITION;
     }

     if (reconfig->flags & SWMCF_SIZE) {
          D_INFO( "SaWMan/TestMan: Window config - ignoring size (%dx%d)!\n", request->bounds.w, request->bounds.h );
          reconfig->flags &= ~SWMCF_SIZE;
     }

     if (reconfig->flags & SWMCF_STACKING) {
          D_INFO( "SaWMan/TestMan: Window config - ignoring stacking (%d)!\n", request->stacking );
          reconfig->flags &= ~SWMCF_STACKING;
     }

     if (reconfig->flags & SWMCF_OPACITY) {
          /* Show? */
          if (request->opacity && !current->opacity) {
               /* Activate scaling. */
               if ( !(reconfig->flags & SWMCF_OPTIONS) )
                    request->options = 0; /* if a flag is not set, corresponding field may not be initialised */

               reconfig->flags   |= SWMCF_OPTIONS;
               request->options  |= DWOP_SCALE;

               ret = LayoutWindowAdd( tm, reconfig->handle );
               if (ret)
                    return ret;
          }
          /* Hide? */
          else if (!request->opacity && current->opacity) {
               LayoutWindowRemove( tm, reconfig->handle );
          }
     }

     return DFB_OK;
}

static DirectResult
window_restack( void                 *context,
                SaWManWindowHandle    handle,
                SaWManWindowHandle    relative,
                SaWManWindowRelation  relation )
{
     //~ if (window->caps & DWCAPS_NODECORATION)
          //~ return DFB_OK;

     D_INFO( "SaWMan/TestMan: Window restack - refusing!\n" );

     return DFB_ACCESSDENIED;
}

static DirectResult
switch_focus( void                 *context,
                SaWManWindowHandle  window )
{
     TestManager        *tm = context;

     D_MAGIC_ASSERT( tm, TestManager );

     D_INFO( "SaWMan/TestMan: Switching focus to %lx\n", window );

     tm->focus_window = window;

     return DFB_OK;
}

static const SaWManCallbacks callbacks = {
     Start:              start_request,
     Stop:               stop_request,
     ProcessAdded:       process_added,
     ProcessRemoved:     process_removed,
     InputFilter:        input_filter,
     WindowPreConfig:    window_preconfig,
     WindowAdded:        window_added,
     WindowRemoved:      window_removed,
     WindowReconfig:     window_reconfig,
     WindowRestack:      window_restack,
     //~ StackResized
     SwitchFocus:        switch_focus
};


int
main( int argc, char** argv )
{
     TestManager tm;

     D_INFO( "SaWMan/TestMan: Initializing...\n" );

     memset( &tm, 0, sizeof(tm) );

     tm.layouts[tm.num_layouts++] = &mosaic_layout;

     D_MAGIC_SET( &tm, TestManager );

     AddApplication( &tm, "Penguins", "df_andi", "--dfb:mode=640x480,force-windowed" );
     AddApplication( &tm, "Windows", "df_window", NULL );


     CHECK( DirectFBInit( &argc, &argv ) );

     CHECK( DirectFBCreate( &tm.dfb ) );

     CHECK( SaWManCreate( &tm.saw ) );

     CHECK( tm.saw->CreateManager( tm.saw, &callbacks, &tm, &tm.manager ) );

     pause();


out:
     D_INFO( "SaWMan/TestMan: Shutting down...\n" );

     if (tm.manager)
          tm.manager->Release( tm.manager );

     if (tm.saw)
          tm.saw->Release( tm.saw );

     if (tm.dfb)
          tm.dfb->Release( tm.dfb );

     D_MAGIC_CLEAR( &tm );

     return 0;
}