3
Copyright 1989,1998 The Open Group
5
Permission to use, copy, modify, distribute, and sell this software and its
6
documentation for any purpose is hereby granted without fee, provided that
7
the above copyright notice appear in all copies and that both that
8
copyright notice and this permission notice appear in supporting
11
The above copyright notice and this permission notice shall be included in
12
all copies or substantial portions of the Software.
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
Except as contained in this notice, the name of The Open Group shall not be
22
used in advertising or otherwise to promote the sale, use or other dealings
23
in this Software without prior written authorization from The Open Group.
25
/* $XFree86: xc/programs/twm/iconmgr.c,v 1.6 2001/12/14 20:01:08 dawes Exp $ */
27
/***********************************************************************
29
* $Xorg: iconmgr.c,v 1.4 2001/02/09 02:05:36 xorgcvs Exp $
31
* Icon Manager routines
33
* 09-Mar-89 Tom LaStrange File Created
35
***********************************************************************/
36
/* $XFree86: xc/programs/twm/iconmgr.c,v 1.6 2001/12/14 20:01:08 dawes Exp $ */
44
#include "add_window.h"
45
#include "siconify.bm"
47
#include <X11/Xmu/CharSet.h>
49
int strcmp(); /* missing from string.h in AUX 2.0 */
52
int iconmgr_textx = siconify_width+11;
54
WList *DownIconManager = NULL;
55
int iconifybox_width = siconify_width;
56
int iconifybox_height = siconify_height;
58
/***********************************************************************
61
* CreateIconManagers - creat all the icon manager windows
70
***********************************************************************
73
void CreateIconManagers()
82
if (Scr->NoIconManagers)
85
if (Scr->siconifyPm == None)
87
Scr->siconifyPm = XCreatePixmapFromBitmapData(dpy, Scr->Root,
88
(char *)siconify_bits, siconify_width, siconify_height, 1, 0, 1);
91
for (p = &Scr->iconmgr; p != NULL; p = p->next)
93
mask = XParseGeometry(p->geometry, &JunkX, &JunkY,
94
(unsigned int *) &p->width, (unsigned int *)&p->height);
97
JunkX = Scr->MyDisplayWidth - p->width -
98
(2 * Scr->BorderWidth) + JunkX;
100
if (mask & YNegative)
101
JunkY = Scr->MyDisplayHeight - p->height -
102
(2 * Scr->BorderWidth) + JunkY;
104
background = Scr->IconManagerC.back;
105
GetColorFromList(Scr->IconManagerBL, p->name, (XClassHint *)NULL,
108
p->w = XCreateSimpleWindow(dpy, Scr->Root,
109
JunkX, JunkY, p->width, p->height, 1,
110
Scr->Black, background);
112
sprintf(str, "%s Icon Manager", p->name);
113
sprintf(str1, "%s Icons", p->name);
115
icon_name = p->icon_name;
119
XSetStandardProperties(dpy, p->w, str, icon_name, None, NULL, 0, NULL);
121
p->twm_win = AddWindow(p->w, TRUE, p);
122
SetMapStateProp (p->twm_win, WithdrawnState);
124
for (p = &Scr->iconmgr; p != NULL; p = p->next)
126
GrabButtons(p->twm_win);
127
GrabKeys(p->twm_win);
131
/***********************************************************************
134
* AllocateIconManager - allocate a new icon manager
137
* name - the name of this icon manager
138
* icon_name - the name of the associated icon
139
* geom - a geometry string to eventually parse
140
* columns - the number of columns this icon manager has
142
***********************************************************************
145
IconMgr *AllocateIconManager(name, icon_name, geom, columns)
154
fprintf(stderr, "AllocateIconManager\n");
155
fprintf(stderr, " name=\"%s\" icon_name=\"%s\", geom=\"%s\", col=%d\n",
156
name, icon_name, geom, columns);
159
if (Scr->NoIconManagers)
162
p = (IconMgr *)malloc(sizeof(IconMgr));
164
p->icon_name = icon_name;
166
p->columns = columns;
177
Scr->iconmgr.lasti->next = p;
178
p->prev = Scr->iconmgr.lasti;
179
Scr->iconmgr.lasti = p;
185
/***********************************************************************
188
* MoveIconManager - move the pointer around in an icon manager
191
* dir - one of the following:
192
* F_FORWICONMGR - forward in the window list
193
* F_BACKICONMGR - backward in the window list
194
* F_UPICONMGR - up one row
195
* F_DOWNICONMGR - down one row
196
* F_LEFTICONMGR - left one column
197
* F_RIGHTICONMGR - right one column
199
* Special Considerations:
202
***********************************************************************
205
void MoveIconManager(dir)
210
int cur_row, cur_col, new_row, new_col;
211
int row_inc, col_inc;
216
cur_row = Active->row;
217
cur_col = Active->col;
218
ip = Active->iconmgr;
227
if ((tmp = Active->next) == NULL)
233
if ((tmp = Active->prev) == NULL)
255
/* If got_it is FALSE ast this point then we got a left, right,
256
* up, or down, command. We will enter this loop until we find
257
* a window to warp to.
267
new_row = ip->cur_rows - 1;
269
new_col = ip->cur_columns - 1;
270
if (new_row >= ip->cur_rows)
272
if (new_col >= ip->cur_columns)
275
/* Now let's go through the list to see if there is an entry with this
278
for (tmp = ip->first; tmp != NULL; tmp = tmp->next)
280
if (tmp->row == new_row && tmp->col == new_col)
291
"%s: unable to find window (%d, %d) in icon manager\n",
292
ProgramName, new_row, new_col);
299
/* raise the frame so the icon manager is visible */
300
if (ip->twm_win->mapped) {
301
XRaiseWindow(dpy, ip->twm_win->frame);
302
XWarpPointer(dpy, None, tmp->icon, 0,0,0,0, 5, 5);
304
if (tmp->twm->title_height) {
305
int tbx = Scr->TBInfo.titlex;
306
int x = tmp->twm->highlightx;
307
XWarpPointer (dpy, None, tmp->twm->title_w, 0, 0, 0, 0,
309
Scr->TitleHeight / 4);
311
XWarpPointer (dpy, None, tmp->twm->w, 0, 0, 0, 0, 5, 5);
316
/***********************************************************************
319
* JumpIconManager - jump from one icon manager to another,
320
* possibly even on another screen
323
* dir - one of the following:
324
* F_NEXTICONMGR - go to the next icon manager
325
* F_PREVICONMGR - go to the previous one
327
***********************************************************************
330
void JumpIconManager(dir)
333
IconMgr *ip, *tmp_ip = NULL;
341
#define ITER(i) (dir == F_NEXTICONMGR ? (i)->next : (i)->prev)
342
#define IPOFSP(sp) (dir == F_NEXTICONMGR ? &(sp->iconmgr) : sp->iconmgr.lasti)
343
#define TEST(ip) if ((ip)->count != 0 && (ip)->twm_win->mapped) \
344
{ got_it = TRUE; break; }
346
ip = Active->iconmgr;
347
for (tmp_ip = ITER(ip); tmp_ip; tmp_ip = ITER(tmp_ip)) {
352
int origscreen = ip->scr->screen;
353
int inc = (dir == F_NEXTICONMGR ? 1 : -1);
355
for (screen = origscreen + inc; ; screen += inc) {
356
if (screen >= NumScreens)
359
screen = NumScreens - 1;
361
sp = ScreenList[screen];
363
for (tmp_ip = IPOFSP (sp); tmp_ip; tmp_ip = ITER(tmp_ip)) {
367
if (got_it || screen == origscreen) break;
376
Bell(XkbBI_MinorError,0,None);
380
/* raise the frame so it is visible */
381
XRaiseWindow(dpy, tmp_ip->twm_win->frame);
383
XWarpPointer(dpy, None, tmp_ip->active->icon, 0,0,0,0, 5, 5);
385
XWarpPointer(dpy, None, tmp_ip->w, 0,0,0,0, 5, 5);
388
/***********************************************************************
391
* AddIconManager - add a window to an icon manager
394
* tmp_win - the TwmWindow structure
396
***********************************************************************
399
WList *AddIconManager(tmp_win)
404
unsigned long valuemask; /* mask for create windows */
405
XSetWindowAttributes attributes; /* attributes for create windows */
408
tmp_win->list = NULL;
410
if (tmp_win->iconmgr || tmp_win->transient || Scr->NoIconManagers)
413
if (LookInList(Scr->IconMgrNoShow, tmp_win->full_name, &tmp_win->class))
415
if (Scr->IconManagerDontShow &&
416
!LookInList(Scr->IconMgrShow, tmp_win->full_name, &tmp_win->class))
418
if ((ip = (IconMgr *)LookInList(Scr->IconMgrs, tmp_win->full_name,
419
&tmp_win->class)) == NULL)
422
tmp = (WList *) malloc(sizeof(WList));
428
InsertInIconManager(ip, tmp, tmp_win);
432
tmp->fore = Scr->IconManagerC.fore;
433
tmp->back = Scr->IconManagerC.back;
434
tmp->highlight = Scr->IconManagerHighlight;
436
GetColorFromList(Scr->IconManagerFL, tmp_win->full_name, &tmp_win->class,
438
GetColorFromList(Scr->IconManagerBL, tmp_win->full_name, &tmp_win->class,
440
GetColorFromList(Scr->IconManagerHighlightL, tmp_win->full_name,
441
&tmp_win->class, &tmp->highlight);
443
h = Scr->IconManagerFont.height + 10;
444
if (h < (siconify_height + 4))
445
h = siconify_height + 4;
447
ip->height = h * ip->count;
452
valuemask = (CWBackPixel | CWBorderPixel | CWEventMask | CWCursor);
453
attributes.background_pixel = tmp->back;
454
attributes.border_pixel = tmp->back;
455
attributes.event_mask = (KeyPressMask | ButtonPressMask |
456
ButtonReleaseMask | ExposureMask |
457
EnterWindowMask | LeaveWindowMask);
458
attributes.cursor = Scr->IconMgrCursor;
459
tmp->w = XCreateWindow (dpy, ip->w, 0, 0, (unsigned int) 1,
460
(unsigned int) h, (unsigned int) 0,
461
CopyFromParent, (unsigned int) CopyFromParent,
462
(Visual *) CopyFromParent, valuemask, &attributes);
465
valuemask = (CWBackPixel | CWBorderPixel | CWEventMask | CWCursor);
466
attributes.background_pixel = tmp->back;
467
attributes.border_pixel = Scr->Black;
468
attributes.event_mask = (ButtonReleaseMask| ButtonPressMask |
470
attributes.cursor = Scr->ButtonCursor;
471
tmp->icon = XCreateWindow (dpy, tmp->w, 5, (int) (h - siconify_height)/2,
472
(unsigned int) siconify_width,
473
(unsigned int) siconify_height,
474
(unsigned int) 0, CopyFromParent,
475
(unsigned int) CopyFromParent,
476
(Visual *) CopyFromParent,
477
valuemask, &attributes);
481
XMapWindow(dpy, tmp->w);
483
XSaveContext(dpy, tmp->w, IconManagerContext, (caddr_t) tmp);
484
XSaveContext(dpy, tmp->w, TwmContext, (caddr_t) tmp_win);
485
XSaveContext(dpy, tmp->w, ScreenContext, (caddr_t) Scr);
486
XSaveContext(dpy, tmp->icon, TwmContext, (caddr_t) tmp_win);
487
XSaveContext(dpy, tmp->icon, ScreenContext, (caddr_t) Scr);
490
if (!ip->twm_win->icon)
492
XMapWindow(dpy, ip->w);
493
XMapWindow(dpy, ip->twm_win->frame);
496
if (Active == NULL) Active = tmp;
501
/***********************************************************************
504
* InsertInIconManager - put an allocated entry into an icon
508
* ip - the icon manager pointer
509
* tmp - the entry to insert
511
***********************************************************************
514
void InsertInIconManager(ip, tmp, tmp_win)
521
int (*compar)(const char *, const char *)
522
= (Scr->CaseSensitive ? strcmp : XmuCompareISOLatin1);
525
if (ip->first == NULL)
532
else if (Scr->SortIconMgr)
534
for (tmp1 = ip->first; tmp1 != NULL; tmp1 = tmp1->next)
536
if ((*compar)(tmp_win->icon_name, tmp1->twm->icon_name) < 0)
539
tmp->prev = tmp1->prev;
541
if (tmp->prev == NULL)
544
tmp->prev->next = tmp;
553
ip->last->next = tmp;
554
tmp->prev = ip->last;
559
void RemoveFromIconManager(ip, tmp)
563
if (tmp->prev == NULL)
564
ip->first = tmp->next;
566
tmp->prev->next = tmp->next;
568
if (tmp->next == NULL)
569
ip->last = tmp->prev;
571
tmp->next->prev = tmp->prev;
574
/***********************************************************************
577
* RemoveIconManager - remove a window from the icon manager
580
* tmp_win - the TwmWindow structure
582
***********************************************************************
585
void RemoveIconManager(tmp_win)
591
if (tmp_win->list == NULL)
595
tmp_win->list = NULL;
598
RemoveFromIconManager(ip, tmp);
600
XDeleteContext(dpy, tmp->icon, TwmContext);
601
XDeleteContext(dpy, tmp->icon, ScreenContext);
602
XDestroyWindow(dpy, tmp->icon);
603
XDeleteContext(dpy, tmp->w, IconManagerContext);
604
XDeleteContext(dpy, tmp->w, TwmContext);
605
XDeleteContext(dpy, tmp->w, ScreenContext);
606
XDestroyWindow(dpy, tmp->w);
614
XUnmapWindow(dpy, ip->twm_win->frame);
619
void ActiveIconManager(active)
622
active->active = TRUE;
624
Active->iconmgr->active = active;
625
DrawIconManagerBorder(active);
628
void NotActiveIconManager(active)
631
active->active = FALSE;
632
DrawIconManagerBorder(active);
635
void DrawIconManagerBorder(tmp)
639
XSetForeground(dpy, Scr->NormalGC, tmp->fore);
640
XDrawRectangle(dpy, tmp->w, Scr->NormalGC, 2, 2,
641
tmp->width-5, tmp->height-5);
643
if (tmp->active && Scr->Highlight)
644
XSetForeground(dpy, Scr->NormalGC, tmp->highlight);
646
XSetForeground(dpy, Scr->NormalGC, tmp->back);
648
XDrawRectangle(dpy, tmp->w, Scr->NormalGC, 0, 0,
649
tmp->width-1, tmp->height-1);
650
XDrawRectangle(dpy, tmp->w, Scr->NormalGC, 1, 1,
651
tmp->width-3, tmp->height-3);
655
/***********************************************************************
658
* SortIconManager - sort the dude
661
* ip - a pointer to the icon manager struture
663
***********************************************************************
666
void SortIconManager(ip)
671
int (*compar)(const char *, const char *)
672
= (Scr->CaseSensitive ? strcmp : XmuCompareISOLatin1);
675
ip = Active->iconmgr;
680
for (tmp1 = ip->first; tmp1 != NULL; tmp1 = tmp1->next)
682
if ((tmp2 = tmp1->next) == NULL)
687
if ((*compar)(tmp1->twm->icon_name, tmp2->twm->icon_name) > 0)
689
/* take it out and put it back in */
690
RemoveFromIconManager(ip, tmp2);
691
InsertInIconManager(ip, tmp2, tmp2->twm);
700
/***********************************************************************
703
* PackIconManager - pack the icon manager windows following
704
* an addition or deletion
707
* ip - a pointer to the icon manager struture
709
***********************************************************************
712
void PackIconManager(ip)
715
int newwidth, i, row, col, maxcol, colinc, rowinc, wheight, wwidth;
720
wheight = Scr->IconManagerFont.height + 10;
721
if (wheight < (siconify_height + 4))
722
wheight = siconify_height + 4;
724
wwidth = ip->width / ip->columns;
732
for (i = 0, tmp = ip->first; tmp != NULL; i++, tmp = tmp->next)
735
if (++col >= ip->columns)
743
new_x = col * colinc;
744
new_y = (row-1) * rowinc;
746
/* if the position or size has not changed, don't touch it */
747
if (tmp->x != new_x || tmp->y != new_y ||
748
tmp->width != wwidth || tmp->height != wheight)
750
XMoveResizeWindow(dpy, tmp->w, new_x, new_y, wwidth, wheight);
757
tmp->height = wheight;
763
ip->cur_columns = maxcol;
764
ip->height = row * rowinc;
767
newwidth = maxcol * colinc;
771
XResizeWindow(dpy, ip->w, newwidth, ip->height);
773
savewidth = ip->width;
775
SetupWindow (ip->twm_win,
776
ip->twm_win->frame_x, ip->twm_win->frame_y,
777
newwidth, ip->height + ip->twm_win->title_height, -1);
778
ip->width = savewidth;