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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <orbit/orbit.h>
#include <ORBitservices/CosNaming.h>
//#include <poa/poa.h>
#include <unistd.h>
#include <directfb.h>
#include "./nitpicker.h"
#include "./nitpicker-skelimpl.c"
#include "./nitevent.h"
#include "examples-toolkit.h"
#include "view.h"
//#include "buffer.h"
#include "client.h"
view *first_view; /* topmost view of view stack */
view *curr_view; /* currently focused view */
unsigned long curr_token; /* token of focused view */
CORBA_Object_base curr_evrec; /* current event receiver */
int screen_width;
int screen_height;
int scr_depth;
IDirectFB *dfb = NULL;
IDirectFBSurface *primary = NULL;
IDirectFBSurface *logo = NULL;
DFBSurfaceDescription dsc;
DFBDisplayLayerConfig dscsurf;
DFBWindowDescription dwinconf;
IDirectFBDisplayLayer *dl;
IDirectFBImageProvider *provider;
IDirectFBWindow *bgwindow = NULL;
IDirectFBSurface *bgsurface;
DFBSurfaceDescription surfdesc;//Background surface discription
IDirectFBSurface *secondary = NULL;
IDirectFBEventBuffer *dfbbuffer;
IDirectFBFont *font;
DFBFontDescription fontdesc;
DFBDisplayLayerConfig dl_config;
DFBGraphicsDeviceDescription gdesc;
IDirectFBWindow* upper;
DFBWindowID id1;
int fontheight;
int err;
int quit = 0;
/*********************************
***Dice Functions ***
********************************/
int dice_obj_eq(CORBA_Object o1, CORBA_Object o2) {
if (!o1 && !o2) return 1;
if (!o1 || !o2) return 0;
// if (l4_task_equal(*o1, *o2)) return 1;
return 0;
}
/**********************************
*** GRAPHICS FUCTIONS ***
**********************************/
int initialize_view(){
int argc = 1;
char *argv[argc];
DirectFBCreate (&dfb);// Create the frame buffer interface
dfb->GetDeviceDescription( dfb, &gdesc ); //Get the discription of the graphics device
dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &dl ); // grab the interface to the screen primary display layer
dl->SetCooperativeLevel( dl, DLSCL_ADMINISTRATIVE );
if (!((gdesc.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&
(gdesc.blitting_flags & DSBLIT_BLEND_COLORALPHA )))
{
dl_config.flags = DLCONF_BUFFERMODE;
dl_config.buffermode = DLBM_BACKSYSTEM;
dl->SetConfiguration( dl, &dl_config );
}
dl->GetConfiguration( dl, &dl_config );
screen_width = dl_config.width;
screen_height = dl_config.height;
/* TODO: pixelformat = dl_config->pixelformat; */
//dl->EnableCursor ( dl, 1 );
fontdesc.flags = DFDESC_HEIGHT;
fontdesc.height = dl_config.width/50;
FILE *fpointer;
if ((fpointer = fopen("./decker.ttf","r")) == NULL){
printf("Font not present.\n");
fclose(fpointer);
return 0;
}
else {
fclose(fpointer);
dfb->CreateFont( dfb, "./decker.ttf", &fontdesc, &font );
font->GetHeight( font, &fontheight );
}
if ((fpointer = fopen("./desktop.png","r")) == NULL){
printf("Background not present.\n");
fclose(fpointer);
return 0;
}
else {
dfb->CreateImageProvider( dfb,
"./desktop.png",
&provider );
surfdesc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS;
surfdesc.width = dl_config.width;
surfdesc.height = dl_config.height;
surfdesc.caps = DSCAPS_SHARED;
dfb->CreateSurface( dfb, &surfdesc, &bgsurface );
provider->RenderTo( provider, bgsurface, NULL );
provider->Release( provider );
}
bgsurface->SetFont( bgsurface, font );
bgsurface->SetColor( bgsurface, 0xCF, 0xCF, 0xFF, 0xFF );
bgsurface->DrawString( bgsurface,
"LINPICER ALPHA",
-1, 0, 0, DSTF_LEFT | DSTF_TOP );
dl->SetBackgroundImage( dl, bgsurface );
dl->SetBackgroundMode( dl, DLBM_IMAGE );
return 1;
}
// This paints the screen black
int clear_screen(){
primary->FillRectangle (primary, 0, 0, screen_width, screen_height);
return 1;
}
// This causes changes to display
int display_refresh(){
primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC);
return 0;
}
int load_images(){
//Open the logo
FILE *fpointer;
if ((fpointer = fopen ("./logo.png", "r")) == NULL){
printf("Logo File Not Present.\n");
fclose(fpointer);
return 0;
}
dfb->CreateImageProvider (dfb, "./logo.png", &provider);
provider->GetSurfaceDescription (provider, &dsc);
/*
* Create a surface based on the description of the provider.
*/
dfb->CreateSurface( dfb, &dsc, &logo );
provider->RenderTo (provider, logo, NULL);
return 1;
}
/**********************************
*** FUNCTIONS FOR INTERNAL USE ***
**********************************/
/*** UTILITY: DRAW RECTANGLE ***/
//static inline void draw_rect(void *dst, int x, int y, int w, int h, int color) {
//
//}
/*** UTILITY: DRAW FRAME AROUND A VIEW ***/
void draw_frame(view *cv) {
//For Later
DFBColor color;
cv->vsurface->SetColor( cv->vsurface,
0x00, 0x30, 0x10, 0xc0 );
cv->vsurface->DrawRectangle( cv->vsurface,
0, 0, cv->sdesc.width, cv->sdesc.height );
cv->vsurface->SetColor( cv->vsurface,
0x80, 0xa0, 0x00, 0x90 );
cv->vsurface->FillRectangle( cv->vsurface,
1, 1,
cv->sdesc.width-2, cv->sdesc.height-2 );
cv->vsurface->Flip( cv->vsurface, NULL, 0 );
//display_refresh();
/* draw frame around the view */
/* if (cv->flags & VIEW_FLAGS_BORDER) {
draw_rect(scr_adr, cv->x - 3, cv->y - 3, cv->w + 6, cv->h + 6, GFX_RGB(0,0,0));
draw_rect(scr_adr, cv->x - 2, cv->y - 2, cv->w + 4, cv->h + 4, color);
draw_rect(scr_adr, cv->x - 1, cv->y - 1, cv->w + 2, cv->h + 2, GFX_RGB(0,0,0));
}*/
}
/*** UTILITY: DRAW VIEW TO PHYSICAL SCREEN ***/
//static inline void draw_view() {
//}
/*** UTILITY: DETERMINE INTERSECTION OF A VIEW WITH SPECIFIED AREA ***
*
* \param v view to check area against
* \param x1, y1 left top point of area
* \param x2, y2 right bottom point of area
* \param dx1, dy1 resulting left top point of intersection area
* \param dx2, dy2 resulting right bottom point of intersection area
*
* \return 1 if view area intersects with specified area
* 0 if there is no intersection
*/
static int intersect( view *v,int x1, int y1, int x2, int y2,
int *dx1, int *dy1, int *dx2, int *dy2) {
// Need to setup mode
int d;//border = (mode && (v->flags & VIEW_FLAGS_BORDER))
// ? BORDER : 0;
//border needed
// *dx1 = MAX(x1, (d = v->x - border));
// *dx2 = MIN(x2, d + v->w + border*2 - 1);
// *dy1 = MAX(y1, (d = v->y - border));
// *dy2 = MIN(y2, d + v->h + border*2 - 1);
return ((*dx1 <= *dx2) && (*dy1 <= *dy2));
}
/*** UTILITY: POSITION THE LABEL SUCH THAT IT IS VISIBLE ***
*
* \param cv current view in the view stack
* \param lv view of the label to position
* \param cx1, cy1 left top point of visible area at current depth
* \param cx2, cy2 right bottom point of visible area
*/
static void place_label_rec(view *cv, view *lv, int cx1, int cy1, int cx2, int cy2) {
int sx1, sy1, sx2, sy2; /* intersection area */
static int cut_w; /* widest visible area of the view */
static int placed; /* flag that indicates a successful placement */
/* sanity check */
if (!cv || !lv) return;
/* init for the first iteration */
if (cv == first_view->next) cut_w = placed = 0;
/* do not replace a label that has already a cosy position */
if (placed) return;
/* if there is an intersection */
if (intersect(cv, cx1, cy1, cx2, cy2, &sx1, &sy1, &sx2, &sy2)) {
/* if we hit the desired view */
if (cv == lv) {
/* if there is enough space, place label */
if ((sx2 - sx1 + 1 > cv->lw) && (sy2 - sy1 + 1 > cv->lh)) {
cv->lx = sx1 + (sx2 - sx1 + 1 - cv->lw)/2;
cv->ly = sy1;
placed = 1; /* mark label as placed */
return;
} else if (sy2 - sy1 + 1 > cv->lh) {
/*
* If the vertical space is big enough to hold the label but
* the available width is not enough, we place the label there
* and remeber the visible width. If we find a wider area
* than the previous, we place the label to the wider area.
* This way, we exhibit as much information of the label
* as possible.
*/
if ((sx2 - sx1 + 1 > cut_w) && !placed) {
cv->lx = sx1;
cv->ly = sy1;
cut_w = sx2 - sx1 + 1;
}
}
}
/* check the next view of the view stack */
if (cv->next == NULL) return;
if (sy1 > cy1) place_label_rec(cv->next, lv, cx1, cy1, cx2, sy1 - 1);
if (sx1 > cx1) place_label_rec(cv->next, lv, cx1, cy1, sx1 - 1, cy2);
if (sx2 < cx2) place_label_rec(cv->next, lv, sx2 + 1, cy1, cx2, cy2);
if (sy2 < cy2) place_label_rec(cv->next, lv, cx1, sy2 + 1, cx2, cy2);
} else place_label_rec(cv->next, lv, cx1, cy1, cx2, cy2);
}
/*** UTILITY: PLACE LABEL TO A VISIBLE POSITION ***/
static void place_label(view *v) {
int old_lx = v->lx, old_ly = v->ly;
int x1 = v->x, x2 = x1 + v->w - 1;
int y1 = v->y, y2 = y1 + v->h - 1;
v->lx = v->x;
v->ly = v->y;
// To fix tonigh
//v->lw = font_string_width (default_font, v->label)
// + font_string_width (default_font, v->client_name) + 5;
//v->lh = font_string_height(default_font, v->label);
// Need to impliment scr_width, scr_height
//place_label_rec(first_view->next, v, MAX(0, x1), MAX(0, y1),
// MIN(scr_width - 1, x2), MIN(scr_height - 1, y2));
//need to impliment mode
/* do not update labels when they are not visible */
//if (mode != MODE_SECURE) return;
refresh_view(v, v, old_lx - v->x, old_ly - v->y, v->lw, v->lh);
refresh_view(v, v, v->lx - v->x, v->ly - v->y, v->lw, v->lh);
}
/*** UTILITY: POSITION LABELS THAT ARE AFFECTED BY SPECIFIED AREA ***/
static void label_area(int x1, int y1, int x2, int y2) {
view *cv = first_view->next; /* ignore the mouse view */
int ix1, iy1, ix2, iy2; /* intersection area */
/* reposition label of each intersecting view but the last one (background) */
for (; cv->next ; cv = cv->next) {
if (intersect(cv, x1, y1, x2, y2, &ix1, &iy1, &ix2, &iy2))
place_label(cv);
}
}
/*** UTILITY: DETERMINE THE LAST STAYTOP VIEW OF THE VIEW STACK ***/
static view *get_last_staytop_view(void) {
view *lv = first_view;
for (; lv && (lv->flags & VIEW_FLAGS_STAYTOP); lv = lv->next)
if (!lv->next || !(lv->next->flags & VIEW_FLAGS_STAYTOP))
break;
return (lv && !(lv->flags & VIEW_FLAGS_STAYTOP)) ? NULL : lv;
}
/*** UTILITY: DETERMINE THE LAST VIEW THAT IS NOT A BACKGROUND VIEW ***/
static view *get_last_normal_view(void) {
view *lv = first_view;
for (; lv && lv->next; lv = lv->next)
if (lv->next->flags & VIEW_FLAGS_BACKGROUND)
break;
return lv;
}
/*** UTILITY: FIND PREDECESSOR VIEW IN VIEW STACK ***/
static view *find_predecessor(view *nv, int behind) {
view *cv = get_last_staytop_view();
for ( ; cv; cv = cv->next)
if (( behind && (cv == nv))
|| (!behind && ((cv->next == nv) || !nv))) break;
return cv ? cv : get_last_staytop_view();
}
/*** SET ACTIVE BACKGROUND TO SPECIFIED BACKGROUND VIEW ***/
static void activate_background(view *v) {
if (dice_obj_eq((CORBA_Object) &curr_view->owner, (CORBA_Object) &v->owner))
CHAIN_LISTELEMENT(view, &first_view, next, get_last_normal_view(), v);
}
///*** DEBUG: DUMP CURRENT VIEW STACK ***/
//static void dump_viewstack(void) {
// view *v = first_view;
//
// printf("Dump view stack:\n");
// for (; v; v = v->next)
// printf(" view %d: xywh=%d,%d,%d,%d\n", v->token, v->x, v->y, v->w, v->h);
//}
/***************************
*** NITPICKER FUNCTIONS ***
***************************/
/*** DRAW VIEWS IN SPECIFIED AREA ***/
void draw_rec(view *cv, view *dst, buffer *exc,
int cx1, int cy1, int cx2, int cy2) {
int sx1, sy1, sx2, sy2;
view *next = cv ? cv->next : NULL;
if (!cv) return;
/* if there is an intersection - subdivide area */
if (!intersect(cv, cx1, cy1, cx2, cy2, &sx1, &sy1, &sx2, &sy2)) {
draw_rec(cv->next, dst, exc, cx1, cy1, cx2, cy2);
return;
}
if (next && (sy1 > cy1))
draw_rec(next, dst, exc, cx1, cy1, cx2, sy1 - 1);
if (next && (sx1 > cx1))
draw_rec(next, dst, exc, cx1, MAX(cy1, sy1), sx1 - 1, MIN(cy2, sy2));
/* draw current view */
if ((!dst || (dst == cv) || (cv->flags & VIEW_FLAGS_TRANSPARENT))) {
draw_frame(cv);
//Need to fix below mode, pop_clipping, push_clipping undefined
// push_clipping(sx1, sy1, sx2 - sx1 + 1, sy2 - sy1 + 1);
// if (!cv->buf || cv->buf != exc) draw_view(cv);
// else if (mode) draw_frame(cv);
// pop_clipping();
}
if (next && (sx2 < cx2))
draw_rec(next, dst, exc, sx2 + 1, MAX(cy1, sy1), cx2, MIN(cy2, sy2));
if (next && (sy2 < cy2))
draw_rec(next, dst, exc, cx1, sy2 + 1, cx2, cy2);
}
/*** LOOK UP VIEW STRUCT BY CLIENT ID AND VIEW ID ***/
view *lookup_view(CORBA_Object tid, int view_id) {
client *c;
//Link error below on undefined dice_obj_eqs
if ((c = find_client(tid)) && (VALID_ID(tid, view_id, c->views, c->max_views))
&& (c->views[view_id].state == STATE_ALLOCATED))
return &c->views[view_id];
return NULL;
}
/*** UPDATE VIEW AREA ON SCREEN ***/
void refresh_view(view *v, view *dst,int x, int y, int w, int h) {
int x1, y1, x2, y2;
if (!v) return;
/* clip argument agains view boundaries */
if (x < 0) x = 0;
if (y < 0) y = 0;
if (x > v->w - w) x = v->w - w;
if (y > v->h - h) y = v->h - h;
/* calculate area to redraw */
x1 = v->x + x - BORDER;
y1 = v->y + y - BORDER;
x2 = v->x + x + w - 1 + BORDER*2;
y2 = v->y + y + h - 1 + BORDER*2;
//need to fix below
draw_rec(first_view, dst, NULL, x1, y1, x2, y2);
}
/*** FIND THE VIEW AT THE SPECIFIED SCREEN POSITION ***/
view * find_view(int x, int y) {
view *cv = first_view->next;
for (; cv; cv = cv->next) {
if ((x >= cv->x) && (x < cv->x + cv->w)
&& (y >= cv->y) && (y < cv->y + cv->h)) return cv;
}
return NULL;
}
/*** SET NEW ACTIVE VIEW ***/
void activate_view(view *nv) {
client *c = nv ? find_client(&nv->owner) : NULL;
if (nv == curr_view) return;
curr_view = nv;
if (curr_view) {
curr_evrec = curr_view->listener;
curr_token = curr_view->token;
}
/* set background for the focused client */
if (c && c->bg) activate_background(c->bg);
/* refresh screen */
// need to fix below
draw_rec(first_view, NULL, NULL, 0, 0, screen_width - 1, screen_height - 1);
//need to fix below
// if (nv && nv->client_name) menubar_set_text(nv->client_name, nv->label);
// else menubar_set_text("", "");
}
/***************************
*** INTERFACE FUNCTIONS ***
***************************/
/*** INTERFACE: CREATE NEW VIEW ***/
CORBA_long nitpicker_new_view(CORBA_Object _obj, int buf_id, const Nitevent listener, CORBA_Environment *ev){
int id;
client *c;
buffer *b;
/* look up client data structure */
if (!(c = find_client(_obj))) return -1;
TRY((id = ALLOC_ID(c->views, c->max_views)) < 0, "Unable to allocate new view id");
memset(&c->views[id], 0, sizeof(view));
c->views[id].state = STATE_ALLOCATED;
c->views[id].flags = VIEW_FLAGS_BORDER | VIEW_FLAGS_LABEL;
//need to fix assignment
c->views[id].owner = (int) &_obj;
c->views[id].token = id;
c->views[id].lw = 32;
c->views[id].lh = 16;
c->views[id].client_name = c->label;
//Setting Initial window size and position
c->views[id].sdesc.width = 300;
c->views[id].sdesc.height = 200;
c->views[id].wdesc.posx = 20;
c->views[id].wdesc.posy = 120;
c->views[id].wdesc.width = c->views[id].sdesc.width;
c->views[id].wdesc.height = c->views[id].sdesc.height;
dl->CreateWindow(dl, &c->views[id].wdesc, &c->views[id].vwindow); //Create a window for each view
c->views[id].vwindow->GetSurface( c->views[id].vwindow, &c->views[id].vsurface);
c->views[id].vwindow->SetOpacity(c->views[id].vwindow, 0xFF );
c->views[id].vwindow->CreateEventBuffer( c->views[id].vwindow, &dfbbuffer );
strncpy(&c->views[id].label[0], "<unknown>", MAX_LABEL);
c->views[id].label[MAX_LABEL - 1] = 0;
//Need to fix listner
if (listener) c->views[id].listener = (int) listener;
if ((b = lookup_buffer(_obj, buf_id))) {
/* assign buffer to view */
c->views[id].buf = b;
/* add view to the buffer's view list */
c->views[id].share_next = b->view;
b->view = &c->views[id];
}
/* place view at top most stack position after staytop views */
CHAIN_LISTELEMENT(view, &first_view, next, get_last_staytop_view(), (&c->views[id]));
return id;
}
/*** INTERFACE: DESTROY VIEW ***/
void nitpicker_destroy_view(CORBA_Object _obj,int view_id, CORBA_Environment *ev) {
int x1, y1, x2, y2;
view *v;
client *c = find_client(_obj);
if (!(v = lookup_view(_obj, view_id))) return;
/* remember original view location */
x1 = v->x - BORDER; x2 = v->x + v->w - 1 + BORDER;
y1 = v->y - BORDER; y2 = v->y + v->h - 1 + BORDER;
/* reset focus if current view has focus */
if (v == curr_view) activate_view(NULL);
/* if view is a background, reset background reference */
if (c && (v == c->bg)) c->bg = NULL;
/* remove view from its buffers list */
if (v->buf) UNCHAIN_LISTELEMENT(view, &v->buf->view, share_next, v);
/* remove view from the view stack list */
UNCHAIN_LISTELEMENT(view, &first_view, next, v);
/* dealloc view label and mark view as free */
v->state = STATE_FREE;
//Need to fix draw rectangle call
/* refresh the original view area and update labels */
draw_rec(first_view, NULL, NULL, x1, y1, x2, y2);
label_area(x1, y1, x2, y2);
}
/*** INTERFACE: SET VIEW POSITION, SIZE, AND BUFFER OFFSET ***/
int nitpicker_set_view_port(CORBA_Object _obj, int view_id, int buf_x, int buf_y, int x, int y, int w, int h, int do_redraw, CORBA_Environment *ev ) {
int x1, y1, x2, y2;
view *v;
if (!(v = lookup_view(_obj, view_id))) return NITPICKER_ERR_ILLEGAL_ID;
/* remember old position */
x1 = v->x; x2 = v->x + v->w - 1;
y1 = v->y; y2 = v->y + v->h - 1;
v->buf_x = buf_x;
v->buf_y = buf_y;
v->x = x;
v->y = y;
v->w = w;
v->h = h;
v->vwindow->Resize(v->vwindow,w,h);
/* determine compound area */
x1 = MIN(x1, x) - BORDER;
y1 = MIN(y1, y) - BORDER;
x2 = MAX(x2, x + w - 1) + 2*BORDER;
y2 = MAX(y2, y + h - 1) + 2*BORDER;
//Need to fix draw rectangle call
/* update affected views */
draw_rec(first_view, NULL, do_redraw ? NULL : v->buf, x1, y1, x2, y2);
/* reposition labels that are affected of the changed area */
if (!(v->flags & VIEW_FLAGS_STAYTOP)) label_area(x1, y1, x2, y2);
return NITPICKER_OK;
}
/*** INTERFACE: POSITION VIEW IN VIEW STACK ***/
int nitpicker_stack_view( CORBA_Object _obj, int view_id,int neighbor_id, int behind, int do_redraw, CORBA_Environment *ev) {
view *v, *nv, *lv;
int done = 0;
if (!(v = lookup_view(_obj, view_id))) return NITPICKER_ERR_ILLEGAL_ID;
nv = (neighbor_id == -1) ? NULL : lookup_view(_obj, neighbor_id);
/* remove view from original view stack position */
UNCHAIN_LISTELEMENT(view, &first_view, next, v);
/* insert view at new stack position */
CHAIN_LISTELEMENT(view, &first_view, next, find_predecessor(nv, behind), v);
/*
* When restacking a view, we move all views of the other clients
* behind the restacked view. This way, we can pull client
* windows in front even if they are locally covered by always-
* on-top windows. To maintain the local order of views in this
* case, we need to move all these views above the new stacking
* position.
*/
lv = v;
while (1) {
view *cv, *sv = get_last_staytop_view()->next;
/* find first view with another owner */
for (cv = sv; cv; cv = cv->next) {
/* if we reached the original view, we are done */
if (!cv || (cv == v)) {
done = 1;
break;
}
//Need to find below dice_obj_eq
/* check if we have a view to move back */
if (!dice_obj_eq((CORBA_Object) &cv->owner,( CORBA_Object) &v->owner))
break;
}
if (done) break;
/* move view back */
UNCHAIN_LISTELEMENT(view, &first_view, next, cv);
CHAIN_LISTELEMENT(view, &first_view, next, lv, cv);
lv = cv;
}
/* refresh affected screen area */
if (do_redraw)
refresh_view(v, 0, 0, 0, v->w, v->h);
label_area(v->x, v->y, v->x + v->w - 1, v->y + v->h - 1);
return NITPICKER_OK;
}
/*** LONGERFACE: REDEFINE VIEW TITLE ***/
int nitpicker_set_view_title( CORBA_Object _obj, int view_id, const CORBA_char * title, CORBA_Environment *ev) {
view *v;
if (!(v = lookup_view(_obj, view_id))) return NITPICKER_ERR_ILLEGAL_ID;
/* set new title */
strncpy(&v->label[0], title, MAX_LABEL);
v->label[MAX_LABEL - 1] = 0;
refresh_view(v, v, 0, 0, v->w, v->h);
return NITPICKER_OK;
}
/*** LONGERFACE: SET MOUSE OPERATING MODE ***/
int nitpicker_set_background(CORBA_Object _obj, int view_id, CORBA_Environment *ev){
client *c = find_client(_obj);
if (!c) return NITPICKER_ERR_ILLEGAL_ID;
/* define new background for the client (invalid view_id -> no background) */
if ((c->bg = lookup_view(_obj, view_id))) {
view *cv;
/* remove background attribute from old background */
c->bg->flags |= VIEW_FLAGS_BACKGROUND;
/* move view in front of the nitpicker background */
UNCHAIN_LISTELEMENT(view, &first_view, next, c->bg);
//More stuff to look up below
if (curr_view && dice_obj_eq(&c->bg->owner, &curr_view->owner))
activate_background(c->bg);
}
return NITPICKER_OK;
}
/*** LONGERFACE: SET MOUSE OPERATING MODE ***/
int nitpicker_set_mousemode(CORBA_Object _obj, int view_id, int mode, CORBA_Environment *ev) {
return NITPICKER_OK;
}
|