~ctwm/ctwm/trunk

« back to all changes in this revision

Viewing changes to workmgr.c

  • Committer: Richard Levitte
  • Author(s): Claude Lecommandeur
  • Date: 2003-02-02 16:57:07 UTC
  • Revision ID: richard@levitte.org-20030202165707-iui8wsl36rsoqwpf
Tags: ctwm-1.2
CTWM version 1.2

Monotone-Parent: b3c7582e14387de7b1a24f0c48c00e8c1f9fbe52
Monotone-Revision: c2a6cbc82eb21a8c0e88685c2b2d50136fe1d772

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
void CreateWorkSpaceManager ()
77
77
{
78
78
    int        mask;
79
 
    Pixel      background;
80
79
    int        lines, vspace, hspace, count, columns;
81
80
    int        width, height, bwidth, bheight;
82
81
    char       *name, *icon_name, *geometry;
97
96
    columns   = Scr->workSpaceMgr.columns;
98
97
    vspace    = Scr->workSpaceMgr.vspace;
99
98
    hspace    = Scr->workSpaceMgr.hspace;
100
 
    cp        = Scr->IconManagerC;
101
99
    font      = Scr->MenuFont;
102
100
 
103
 
    GetColor (Scr->Monochrome, &(cp.back), "gray70");
104
 
 
105
101
    count = 0;
106
102
    for (blist = Scr->workSpaceMgr.buttonList; blist != NULL; blist = blist->next) count++;
107
103
 
135
131
        bheight = (height - ((lines   + 1) * vspace)) / lines;
136
132
    }
137
133
 
138
 
 
139
 
    background = Scr->workSpaceMgr.cp.back;
140
 
    GetColorFromList(Scr->IconManagerBL, name, (XClassHint *)NULL, &background);
141
 
 
 
134
    cp = Scr->IconManagerC;
142
135
    Scr->workSpaceMgr.w = XCreateSimpleWindow (dpy, Scr->Root, x, y, width, height, 0, Scr->Black, cp.back);
143
136
 
144
137
    i = 0;
158
151
    Scr->workSpaceMgr.twm_win->occupation = fullOccupation;
159
152
    XSelectInput (dpy, Scr->workSpaceMgr.w, ButtonPressMask |
160
153
                                            ButtonReleaseMask |
 
154
                                            KeyPressMask |
 
155
                                            KeyReleaseMask |
161
156
                                            ExposureMask);
162
157
 
163
158
    SetMapStateProp (Scr->workSpaceMgr.twm_win, WithdrawnState);
169
164
    Scr->workSpaceMgr.width     = width;
170
165
    Scr->workSpaceMgr.height    = height;
171
166
    Scr->workSpaceMgr.count     = count;
172
 
    Scr->workSpaceMgr.cp        = Scr->IconManagerC;
 
167
    Scr->workSpaceMgr.cp        = cp;
173
168
    Scr->workSpaceMgr.font      = Scr->MenuFont;
174
169
 
175
170
    CreateOccupyWindow ();
232
227
        XClearWindow (dpy, Scr->Root);
233
228
    }
234
229
    for (twmWin = &(Scr->TwmRoot); twmWin != NULL; twmWin = twmWin->next) {
235
 
        if (OCCUPY (twmWin, oldscr) && ! OCCUPY (twmWin, newscr)) {
236
 
            Vanish (twmWin);
237
 
        }
238
 
        if (! OCCUPY (twmWin, oldscr) && OCCUPY (twmWin, newscr)) {
239
 
            DisplayWin (twmWin);
240
 
        }
 
230
        if (OCCUPY (twmWin, oldscr)) {
 
231
            if (twmWin->mapped == FALSE) {
 
232
                if ((twmWin->icon_on == TRUE) && (twmWin->icon_w)) {
 
233
                    XUnmapWindow(dpy, twmWin->icon_w);
 
234
                    IconDown (twmWin);
 
235
                }
 
236
            }
 
237
            else
 
238
            if (! OCCUPY (twmWin, newscr)) {
 
239
                Vanish (twmWin);
 
240
            }
 
241
        }
 
242
    }
 
243
    for (twmWin = &(Scr->TwmRoot); twmWin != NULL; twmWin = twmWin->next) {
 
244
        if (OCCUPY (twmWin, newscr)) {
 
245
            if (twmWin->mapped == FALSE) {
 
246
                if ((twmWin->icon_on == TRUE) && (twmWin->icon_w)) {
 
247
                    IconUp (twmWin);
 
248
                    XMapRaised(dpy, twmWin->icon_w);
 
249
                }
 
250
            }
 
251
            else
 
252
            if (! OCCUPY (twmWin, oldscr)) {
 
253
                DisplayWin (twmWin);
 
254
            }
 
255
        }
 
256
    }
 
257
/*
 
258
   Reorganize window lists
 
259
*/
 
260
    for (twmWin = &(Scr->TwmRoot); twmWin != NULL; twmWin = twmWin->next) {
241
261
        wl = twmWin->list;
242
262
        if (wl == NULL) continue;
243
263
        if (OCCUPY (wl->iconmgr->twm_win, newscr)) continue;
321
341
            useBackgroundInfo = True;
322
342
        }
323
343
    }
324
 
    blist->next    = NULL;
325
 
    blist->number  = scrnum++;
 
344
    blist->next        = NULL;
 
345
    blist->number      = scrnum++;
326
346
    if (Scr->workSpaceMgr.buttonList == NULL) {
327
347
        Scr->workSpaceMgr.buttonList = blist;
328
348
    }
383
403
        XrmDestroyDatabase (db);
384
404
        db = NULL;
385
405
    }
 
406
    if (twm_win->iconmgr) /* someone try to modify occupation of icon managers */
 
407
        twm_win->occupation = 1 << Scr->workSpaceMgr.activeWSPC->number;
 
408
 
386
409
    if ((twm_win->occupation & fullOccupation) == 0)
387
410
        twm_win->occupation = 1 << Scr->workSpaceMgr.activeWSPC->number;
388
411
 
389
412
    XChangeProperty (dpy, twm_win->w, _XA_WM_WORKSPACES, _XA_WM_WORKSPACES, 32, 
390
413
                     PropModeReplace, (unsigned char *) &twm_win->occupation, 1);
391
414
 
 
415
/* kludge */
392
416
    if (OCCUPY (twm_win, Scr->workSpaceMgr.activeWSPC)) {
393
 
                /* use WM_STATE if enabled */
394
417
        if (GetWMState (twm_win->w, &state, &icon) != 0) {
395
418
            if (state == InactiveState) SetMapStateProp (twm_win, NormalState);
396
419
        }
397
 
        else {
398
 
            SetMapStateProp (twm_win, NormalState);
399
 
        }
400
420
    }
401
421
    else {
402
 
                /* use WM_STATE if enabled */
403
422
        if (GetWMState (twm_win->w, &state, &icon) != 0) {
404
423
            if (state == NormalState) SetMapStateProp (twm_win, InactiveState);
405
424
        }
406
 
        else {
 
425
        else
 
426
        if (twm_win->wmhints->initial_state == NormalState) {
407
427
            SetMapStateProp (twm_win, InactiveState);
408
428
        }
409
429
    }
461
481
    TwmWindow    *twmWin;
462
482
    ButtonList   *blist;
463
483
    OccupyWindow *occupyW;
464
 
    IconMgr      *save;
465
484
 
466
485
    if (! workSpaceManagerActive) return;
467
486
    if (occupyWin == (TwmWindow*) 0) return;
489
508
    else
490
509
    if (buttonW == occupyW->OK) {
491
510
        if (occupyW->tmpOccupation == 0) return;
492
 
 
493
 
        save = Scr->iconmgr;
494
 
        Scr->iconmgr = Scr->workSpaceMgr.buttonList->iconmgr;
495
511
        occupyWin->occupation = occupyW->tmpOccupation & ~occupyWin->occupation;
496
512
        AddIconManager (occupyWin);
497
513
        occupyWin->occupation = occupyW->tmpOccupation;
498
 
        Scr->iconmgr = save;
499
514
        RemoveIconManager (occupyWin);
500
515
        if (! OCCUPY (occupyWin, Scr->workSpaceMgr.activeWSPC)) Vanish (occupyWin);
501
516
        Vanish (occupyW->twm_win);
525
540
    if (ButtonPressed == -1) XUngrabPointer (dpy, CurrentTime);
526
541
}
527
542
 
 
543
ChangeLabel (event)
 
544
XEvent *event;
 
545
{
 
546
    ButtonList *blist;
 
547
    Window     buttonW;
 
548
    int        len, i, lname;
 
549
    char       key [16], k;
 
550
    char       name [128];
 
551
 
 
552
    buttonW = event->xkey.subwindow;
 
553
 
 
554
    if (buttonW == 0) return; /* icon */
 
555
    blist = Scr->workSpaceMgr.buttonList;
 
556
    while (blist != NULL) {
 
557
        if (blist->w == buttonW) break;
 
558
        blist = blist->next;
 
559
    }
 
560
    if (blist == NULL) return;
 
561
    strcpy (name, blist->label);
 
562
    lname = strlen (name);
 
563
    len   = XLookupString (event, key, 16, NULL, NULL);
 
564
    for (i = 0; i < len; i++) {
 
565
        k = key [i];
 
566
        if (isprint (k)) {
 
567
            name [lname++] = k;
 
568
        }
 
569
        else
 
570
        if ((k == 127) || (k == 8)) {
 
571
            if (lname != 0) lname--;
 
572
        }
 
573
        else
 
574
            break;
 
575
    }
 
576
    name [lname] = '\0';
 
577
    SetButtonLabel (blist, name);
 
578
}
 
579
 
528
580
OccupyAll (twm_win)
529
581
TwmWindow *twm_win;
530
582
{
581
633
    XWindowAttributes winattrs;
582
634
    unsigned long eventMask;
583
635
 
584
 
    if (tmp_win->mapped == FALSE) {
585
 
        if (tmp_win->icon_on == TRUE) {
586
 
            XUnmapWindow (dpy, tmp_win->icon_w);
587
 
        }
588
 
        return;
589
 
    }
590
636
    XGetWindowAttributes(dpy, tmp_win->w, &winattrs);
591
637
    eventMask = winattrs.your_event_mask;
592
638
 
609
655
    XWindowAttributes winattrs;
610
656
    unsigned long eventMask;
611
657
 
612
 
    if (tmp_win->mapped == FALSE) {
613
 
        if (tmp_win->icon_on == TRUE) {
614
 
            XMapWindow (dpy, tmp_win->icon_w);
615
 
        }
616
 
        return;
617
 
    }
618
 
 
619
 
    XGetWindowAttributes(dpy, tmp_win->w, &winattrs);
620
 
    eventMask = winattrs.your_event_mask;
621
 
 
622
658
    XMapWindow(dpy, tmp_win->w);
623
659
    XMapWindow(dpy, tmp_win->frame);
624
660
    SetMapStateProp (tmp_win, NormalState);
822
858
    }
823
859
}
824
860
 
 
861
void SetButtonLabel (blist, label)
 
862
ButtonList *blist;
 
863
char       *label;
 
864
{
 
865
    Window     w;
 
866
    int        bwidth, bheight, width, height;
 
867
    ColorPair  cp;
 
868
    MyFont     font;
 
869
    int        strWid, strHei, hspace, vspace;
 
870
 
 
871
    width   = Scr->workSpaceMgr.width;
 
872
    height  = Scr->workSpaceMgr.height;
 
873
    bwidth  = Scr->workSpaceMgr.bwidth;
 
874
    bheight = Scr->workSpaceMgr.bheight;
 
875
    font    = Scr->workSpaceMgr.font;
 
876
 
 
877
    w    = blist->w;
 
878
    blist->label = realloc (blist->label, (strlen (label) + 1));
 
879
    strcpy (blist->label, label);
 
880
    cp   = blist->cp;
 
881
 
 
882
    strHei = font.font->max_bounds.ascent + font.font->max_bounds.descent;
 
883
    vspace = ((bheight + strHei) / 2) - font.font->max_bounds.descent;
 
884
    XClearWindow (dpy, blist->w);
 
885
    if (blist == Scr->workSpaceMgr.activeWSPC) SetButton (blist->w, on);
 
886
    else SetButton (blist->w, off);
 
887
    FBF (cp.fore, cp.back, font.font->fid);
 
888
    strWid = XTextWidth (font.font, label, strlen (label));
 
889
    hspace = (bwidth - strWid) / 2;
 
890
    if (hspace < 3) hspace = 3;
 
891
    XDrawString (dpy, w, Scr->NormalGC, hspace, vspace, label, strlen (label));
 
892
}
 
893
 
825
894
int GetMaskFromResource (res)
826
895
char *res;
827
896
{