~ubuntu-branches/ubuntu/quantal/openmotif/quantal

« back to all changes in this revision

Viewing changes to demos/programs/workspace/wsmStruct.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bauer
  • Date: 2010-06-23 12:12:31 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100623121231-u89gxdp51sg9wjj2
Tags: 2.3.0-1
* New Maintainer (Closes: #379258) 
* Acknowledge NMU changes
* New upstream release (Closes: #494375)
* Get rid of security patches as they are already part of new upstream
  release (00-xpmvuln.openmotif.patch, 342092-CVE-2005-3964.patch)
* Bump Standards to 3.8.4
* Added {misc:Depends} to make the package lintian cleaner
* Fix weak-library-dev-dependency by adding ${binary:Version}) for the
  -dev Package of openmotif
* Let package depend on autotools-dev to use newer autotools-helper-files
* Work around an autoconf-bug (Gentoo-Bug #1475)
* Added Client-side anti-aliased fonts support via XFT
* Added UTF-8 and UTF8_STRING atom support
* Ability to show text and pixmaps in Label, LabelGadget and all
  derived widgets
* Support of PNG/JPEG image formats in the same way as XPM is supported
* Increase FILE_OFFSET_BITS to 64 to show files >2GB in file-selector
  Idea taken from Magne Oestlyngen (Closes: #288537)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 *  @OPENGROUP_COPYRIGHT@
 
3
 *  COPYRIGHT NOTICE
 
4
 *  Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
 
5
 *  Copyright (c) 1996, 1997, 1998, 1999, 2000 The Open Group
 
6
 *  ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
 
7
 *  the full copyright text.
 
8
 *  
 
9
 *  This software is subject to an open license. It may only be
 
10
 *  used on, with or for operating systems which are themselves open
 
11
 *  source systems. You must contact The Open Group for a license
 
12
 *  allowing distribution and sublicensing of this software on, with,
 
13
 *  or for operating systems which are not Open Source programs.
 
14
 *  
 
15
 *  See http://www.opengroup.org/openmotif/license for full
 
16
 *  details of the license agreement. Any use, reproduction, or
 
17
 *  distribution of the program constitutes recipient's acceptance of
 
18
 *  this agreement.
 
19
 *  
 
20
 *  EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
 
21
 *  PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
22
 *  KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
 
23
 *  WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
 
24
 *  OR FITNESS FOR A PARTICULAR PURPOSE
 
25
 *  
 
26
 *  EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
 
27
 *  NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT,
 
28
 *  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
29
 *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED
 
30
 *  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
31
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 
32
 *  ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
 
33
 *  EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
 
34
 *  POSSIBILITY OF SUCH DAMAGES.
 
35
*/ 
 
36
/* 
 
37
 * HISTORY
 
38
*/ 
 
39
#ifdef REV_INFO
 
40
#ifndef lint
 
41
static char rcsid[] = "$TOG: wsmStruct.c /main/7 1997/05/02 10:04:46 dbl $"
 
42
#endif
 
43
#endif
 
44
#include <stdio.h>
 
45
#include <Xm/Xm.h>
 
46
 
 
47
 
 
48
#include "wsm.h"
 
49
#include "wsmData.h"
 
50
#include "wsmStruct.h"
 
51
#include "wsm_cb.h"
 
52
#include "wsmDebug.h"
 
53
#include "xrmLib.h"
 
54
 
 
55
extern AtomStruct atoms;
 
56
extern Space *space_list;
 
57
extern Space *all_space;
 
58
extern Space *current_space;
 
59
extern WorkWindow *work_windows;
 
60
extern XrmQuark *space_qlist;
 
61
extern XrmQuark *window_attribq;
 
62
extern XrmQuark *icon_attribq;
 
63
extern XrmQuark *global_attribq;
 
64
extern WSMAttribute *window_attrib_list;
 
65
extern WSMAttribute *icon_attrib_list;
 
66
extern WSMAttribute *global_attrib_list;
 
67
extern int num_window_attrib;
 
68
extern int num_icon_attrib;
 
69
extern int num_global_attrib;
 
70
extern Boolean diffs_allowed;
 
71
extern Widget shell;
 
72
extern Display *dsp;
 
73
extern Boolean connected;
 
74
 
 
75
static char* GetWMName(
 
76
Window, Boolean
 
77
);
 
78
static char* GetWMClient(
 
79
Window, Boolean
 
80
);
 
81
static char* GetWMRole(
 
82
Window, Boolean
 
83
);
 
84
static char* GetWMCount(
 
85
XrmQuark,XrmQuark
 
86
);
 
87
XrmQuarkList GetSpecifierQList(
 
88
Window, Boolean
 
89
);
 
90
 
 
91
void AddWindowToSpace(
 
92
Space*,WorkWindow*
 
93
);
 
94
 
 
95
char *Get_SM_CLIENT_ID(
 
96
Display*, Window
 
97
);
 
98
 
 
99
char *Get_WM_WINDOW_ROLE(
 
100
Display*, Window
 
101
);
 
102
 
 
103
Colormap default_cmap = 0;
 
104
 
 
105
 
 
106
/**********************************************************************/
 
107
/*                        INTERNAL STRUCTURE CODE                     */
 
108
/**********************************************************************/
 
109
 
 
110
 
 
111
 
 
112
/*------------------------------------------------------------------
 
113
                            CreateSpace
 
114
 
 
115
  ------------------------------------------------------------------*/
 
116
Space* 
 
117
CreateSpace(XrmQuark name, char *str)
 
118
{
 
119
  WorkWindowList *w_list;
 
120
  Space *s, *s2;
 
121
  s = (Space*)XtMalloc(sizeof(Space));
 
122
  s->nameq = name;
 
123
  s->w_list = NULL;
 
124
  if (all_space->w_list != NULL)
 
125
    {
 
126
      w_list = all_space->w_list;
 
127
      while (w_list != NULL)    
 
128
        {
 
129
          AddWindowToSpace(s,w_list->work_win);
 
130
          w_list = w_list->next;
 
131
        }      
 
132
      }
 
133
  s->next = NULL;
 
134
  strcpy(s->name, str); 
 
135
  strcpy(s->background,"None");
 
136
  strcpy(s->pixmap_name,"None");
 
137
  s->pixel = 0;
 
138
  s->pixmap = None;
 
139
  s->pixmap_label = None;
 
140
  if (space_list == NULL)
 
141
    {
 
142
      current_space = s;
 
143
      space_list = s;
 
144
    }
 
145
  else 
 
146
    {
 
147
      s2 = space_list;
 
148
      while (s2->next != NULL)
 
149
        s2 = s2->next;
 
150
      s2->next = s;
 
151
    }
 
152
  return s;
 
153
}
 
154
 
 
155
/*------------------------------------------------------------------
 
156
                            SetSpacePixel
 
157
 
 
158
  ------------------------------------------------------------------*/
 
159
Boolean
 
160
SetSpacePixel(Space *s, char *name)
 
161
{
 
162
  Boolean retval = True;
 
163
  XColor a_color;
 
164
  XColor def_color;
 
165
  
 
166
  if (default_cmap == 0)
 
167
    default_cmap = DefaultColormap(dsp,0);
 
168
  if (XAllocNamedColor(dsp,default_cmap,name,&a_color, &def_color)==0)
 
169
    return False;
 
170
  s->pixel = a_color.pixel;
 
171
  strcpy(s->background,name);
 
172
  s->pixmap = None;
 
173
  return retval;
 
174
}
 
175
 
 
176
 
 
177
 
 
178
 
 
179
 
 
180
/*------------------------------------------------------------------
 
181
                            SpacePixelSet
 
182
 
 
183
  ------------------------------------------------------------------*/
 
184
Boolean
 
185
SpacePixelSet(Space *s)
 
186
{
 
187
  if (strcmp("None",s->background) == 0)
 
188
    return False;
 
189
  if (s->pixmap != None) 
 
190
    return False;
 
191
  else return True;
 
192
}
 
193
 
 
194
 
 
195
 
 
196
/*------------------------------------------------------------------
 
197
                            SetSpacePixmap
 
198
 
 
199
  ------------------------------------------------------------------*/
 
200
Boolean
 
201
SetSpacePixmap(Space *s, char *name)
 
202
{
 
203
  unsigned int width, height;
 
204
  Window root = XRootWindowOfScreen(XtScreen(shell));
 
205
 
 
206
  s -> pixmap = XmGetPixmapByDepth(XtScreen(shell), name, 
 
207
                              BlackPixel(XtDisplay(shell), 0),
 
208
                              WhitePixel(XtDisplay(shell), 0),
 
209
                              DefaultDepth(dsp, 0));
 
210
  if (s -> pixmap == XmUNSPECIFIED_PIXMAP) 
 
211
    {
 
212
      fprintf(stderr, "can't get pixmap for %s\n", name);
 
213
      return False;
 
214
    }
 
215
 
 
216
  s->background[0] = '"';
 
217
  s->background[1] = '\0';
 
218
  strcat(s->background,name);
 
219
  PRINT("s->background is %s\n",name); 
 
220
  return True;
 
221
}
 
222
 
 
223
 
 
224
 
 
225
/*------------------------------------------------------------------
 
226
                            SpacePixmapSet
 
227
 
 
228
  ------------------------------------------------------------------*/
 
229
Boolean
 
230
SpacePixmapSet(Space *s)
 
231
{
 
232
  if (strcmp("None",s->background) == 0)
 
233
    return False;
 
234
  if (s->pixmap == None)
 
235
    return False;
 
236
  else return True;
 
237
}
 
238
 
 
239
 
 
240
 
 
241
 
 
242
/*------------------------------------------------------------------
 
243
                            SetSpaceLabelPixmap
 
244
 
 
245
  ------------------------------------------------------------------*/
 
246
Boolean
 
247
SetSpaceLabelPixmap(Space *s, char *name)
 
248
{
 
249
  unsigned int width, height;
 
250
  Pixmap bitmap;
 
251
  int status;
 
252
  GC gc;
 
253
  XGCValues values;
 
254
  Window root = XRootWindowOfScreen(XtScreen(shell));
 
255
 
 
256
  PRINT("setting space %s label pixmap to %s\n", s->name,name);
 
257
  if (strcmp(name,"None") == 0 || strcmp(name,"none")== 0)
 
258
    return False;
 
259
  status = XReadBitmapFile(dsp,root,name,&width,&height,&bitmap,
 
260
                           (int *)NULL, (int *)NULL);
 
261
 
 
262
  if (status == BitmapOpenFailed)
 
263
    {
 
264
      fprintf(stderr, "can't open file %s\n", name);
 
265
      return False;
 
266
    }
 
267
  else if (status == BitmapFileInvalid)
 
268
    {
 
269
      fprintf(stderr, "bad bitmap format file: %s\n", name);
 
270
      return False;
 
271
    }
 
272
  else if (status == BitmapNoMemory)
 
273
    {
 
274
      fprintf(stderr, "insufficient memory for bitmap file: %s\n", name);
 
275
      return False;
 
276
    }
 
277
  values.foreground = BlackPixel(XtDisplay(shell),0);
 
278
  values.background = WhitePixel(XtDisplay(shell),0);
 
279
  gc = XCreateGC(dsp,root,GCForeground|GCBackground,&values);
 
280
  if (s->pixmap_label != None) XFreePixmap(dsp,s->pixmap_label);
 
281
  s->pixmap_label = XCreatePixmap(dsp,root,width,height,
 
282
                            (unsigned int)DefaultDepth(dsp,0));
 
283
  XCopyPlane(dsp,bitmap,s->pixmap_label,gc,0,0,width,height,0,0,
 
284
            (unsigned long)1);
 
285
/*  s->pixmap = XCreatePixmapFromBitmapData(dsp,root,name,width,height,
 
286
                                          BlackPixel(XtDisplay(shell),0),
 
287
                                          WhitePixel(XtDisplay(shell),0),
 
288
                                          (unsigned int)
 
289
                                          DefaultDepth(dsp,
 
290
                                                       DefaultScreen(dsp)));*/
 
291
  strcpy(s->pixmap_name,name);
 
292
  PRINT("s->pixmap_name is %s\n",name);
 
293
  XFreeGC(dsp, gc);
 
294
  return True;
 
295
}
 
296
 
 
297
 
 
298
 
 
299
/*------------------------------------------------------------------
 
300
                            SpaceLabelPixmapSet
 
301
 
 
302
  ------------------------------------------------------------------*/
 
303
Boolean
 
304
SpaceLabelPixmapSet(Space *s)
 
305
{
 
306
  if (s->pixmap_label == None)
 
307
    return False;
 
308
  else return True;
 
309
}
 
310
 
 
311
 
 
312
 
 
313
 
 
314
/*------------------------------------------------------------------
 
315
                            CreateInternalStructure
 
316
 
 
317
  ------------------------------------------------------------------*/
 
318
Boolean 
 
319
CreateInternalStructure(WorkWindow *w_window,XrmQuark *rooms_qlist)
 
320
{
 
321
  Space *space;
 
322
  int j;
 
323
  Boolean in_current_space = False;
 
324
  if (w_window->all_workspaces) 
 
325
    {
 
326
      /* create internal structures */
 
327
      for (j=0, space = space_list; space !=NULL; space = space->next, j++)
 
328
        {
 
329
          if (space == current_space) 
 
330
            in_current_space = True;
 
331
          AddSpaceToWindow(space, w_window);
 
332
          AddWindowToSpace(space, w_window);
 
333
        }
 
334
    }
 
335
  else if (rooms_qlist == NULL) 
 
336
    {
 
337
      AddSpaceToWindow(current_space,w_window);
 
338
      AddWindowToSpace(current_space,w_window);
 
339
      in_current_space = True;
 
340
    }
 
341
  else
 
342
    {
 
343
      /* create internal structures */
 
344
      for (j=0; rooms_qlist[j] != NULLQUARK; j++)
 
345
        {
 
346
          space = GetSpace(rooms_qlist[j]);
 
347
          if (space == NULL)
 
348
            space = CreateSpace(rooms_qlist[j], XrmQuarkToString(rooms_qlist[j]));
 
349
          if (space == current_space) 
 
350
            in_current_space = True;
 
351
          AddSpaceToWindow(space, w_window);
 
352
          AddWindowToSpace(space, w_window);
 
353
        }
 
354
    }
 
355
 
 
356
  if (w_window->all_workspaces)
 
357
    AddWindowToSpace(all_space,w_window);
 
358
  return in_current_space;
 
359
}
 
360
 
 
361
/*------------------------------------------------------------------
 
362
                            CreateWorkWindow
 
363
 
 
364
  ------------------------------------------------------------------*/
 
365
WorkWindow* 
 
366
CreateWorkWindow(Window window)
 
367
{
 
368
  WorkWindow *w, *w2;
 
369
  int i;
 
370
 
 
371
  w = GetWorkWindow(window);
 
372
 
 
373
  /* if wsm already knows about this window then just
 
374
     set mapped = True and return the window */
 
375
  if (w != NULL) 
 
376
    {
 
377
      w->mapped = True;
 
378
      return w;
 
379
    }
 
380
 
 
381
  w = (WorkWindow *)XtMalloc(sizeof(WorkWindow));
 
382
  w->window = window;
 
383
  w->used = True;
 
384
 
 
385
  switch (_WSMGetConfigFormatType(window))
 
386
    {
 
387
    case WSM_GLOBAL_FMT:
 
388
      w->attrib_qlist = global_attribq;
 
389
      w->attrib_list = global_attrib_list;
 
390
      w->num_attrib_list = num_global_attrib;
 
391
      w->all_workspaces = True;
 
392
      w->specifier_qlist = GetSpecifierQList(0,False);
 
393
      w->name = GetWMName(0,False);
 
394
      break;
 
395
      
 
396
    case WSM_WINDOW_FMT:
 
397
      w->attrib_qlist = window_attribq;
 
398
      w->attrib_list = window_attrib_list;
 
399
      w->num_attrib_list = num_window_attrib;
 
400
      w->all_workspaces = False;
 
401
      w->specifier_qlist = GetSpecifierQList(window,False);
 
402
      w->name = GetWMName(window,False);
 
403
      break;
 
404
      
 
405
    case WSM_ICON_FMT:
 
406
      w->attrib_qlist = icon_attribq;
 
407
      w->attrib_list = icon_attrib_list;
 
408
      w->num_attrib_list = num_icon_attrib;
 
409
      w->all_workspaces = True;
 
410
      w->specifier_qlist = GetSpecifierQList(window, True);
 
411
      w->name = GetWMName(window,True);
 
412
      break;
 
413
 
 
414
    default:
 
415
      break;
 
416
    }
 
417
  
 
418
  w->next = NULL;
 
419
  w->prev = NULL;
 
420
  w->last_space = NULL;
 
421
  w->s_list = NULL;
 
422
  w->linked = False;
 
423
  w->mapped = True;
 
424
  w->win_data = (WSMWinData*)XtMalloc(w->num_attrib_list*sizeof(WSMWinData));
 
425
  for (i = 0; i < w->num_attrib_list; i++)
 
426
    {
 
427
      w->win_data[i].nameq = w->attrib_qlist[i];
 
428
      w->win_data[i].type = WSM_NONE;
 
429
      w->win_data[i].data.value = -1;
 
430
    }
 
431
  if (work_windows == NULL)
 
432
    work_windows = w;
 
433
  else
 
434
    {
 
435
      w2 = work_windows;
 
436
      while (w2->next != NULL)
 
437
        w2 = w2->next;
 
438
      w2->next = w;
 
439
      w->prev = w2;
 
440
    }
 
441
 
 
442
  if (w->all_workspaces)
 
443
    {
 
444
      CreateInternalStructure(w,NULL);
 
445
      UpdateBothList(all_space);
 
446
    }
 
447
 
 
448
  if (_WSMGetConfigFormatType(window) == WSM_WINDOW_FMT)
 
449
    {
 
450
      PRINT("XSelectInput ");
 
451
      print_window(w);
 
452
      XSelectInput(dsp,window,StructureNotifyMask);
 
453
    }
 
454
 
 
455
  return w;
 
456
}
 
457
 
 
458
 
 
459
 
 
460
/*------------------------------------------------------------------
 
461
                            ReCreateWorkWindow
 
462
 
 
463
  ------------------------------------------------------------------*/
 
464
WorkWindow* 
 
465
ReCreateWorkWindow(Window window)
 
466
{
 
467
  WorkWindow *w;
 
468
  int i;
 
469
 
 
470
  w = GetWorkWindow(window);
 
471
  
 
472
  if (w == NULL)
 
473
    return CreateWorkWindow(window);
 
474
 
 
475
  switch (_WSMGetConfigFormatType(window))
 
476
    {
 
477
    case WSM_GLOBAL_FMT:
 
478
      w->attrib_qlist = global_attribq;
 
479
      w->attrib_list = global_attrib_list;
 
480
      w->num_attrib_list = num_global_attrib;
 
481
      break;
 
482
      
 
483
    case WSM_WINDOW_FMT:
 
484
      w->attrib_qlist = window_attribq;
 
485
      w->attrib_list = window_attrib_list;
 
486
      w->num_attrib_list = num_window_attrib;
 
487
      break;
 
488
      
 
489
    case WSM_ICON_FMT:
 
490
      w->attrib_qlist = icon_attribq;
 
491
      w->attrib_list = icon_attrib_list;
 
492
      w->num_attrib_list = num_icon_attrib;
 
493
      break;
 
494
 
 
495
    default:
 
496
      break;
 
497
    }
 
498
  
 
499
  XtFree((XtPointer)w->win_data);
 
500
  w->win_data = (WSMWinData*)XtMalloc(w->num_attrib_list*sizeof(WSMWinData));
 
501
  for (i = 0; i < w->num_attrib_list; i++)
 
502
    {
 
503
      w->win_data[i].nameq = w->attrib_qlist[i];
 
504
      w->win_data[i].type = WSM_NONE;
 
505
      w->win_data[i].data.value = -1;
 
506
    }
 
507
 
 
508
  return w;
 
509
}
 
510
 
 
511
 
 
512
 
 
513
/*------------------------------------------------------------------
 
514
                              GetSpace
 
515
 
 
516
  ------------------------------------------------------------------*/
 
517
Space* 
 
518
GetSpace(XrmQuark name)
 
519
{
 
520
  Space *s;
 
521
  s = space_list;
 
522
  while (s != NULL)
 
523
    {
 
524
      if (s->nameq == name)
 
525
        return s;
 
526
      s = s->next;
 
527
    }
 
528
  PRINT("returning NULL space\n");
 
529
  return NULL;
 
530
}
 
531
 
 
532
 
 
533
 
 
534
/*------------------------------------------------------------------
 
535
                              GetSpaceFromName
 
536
 
 
537
  ------------------------------------------------------------------*/
 
538
Space* 
 
539
GetSpaceFromName(char *name)
 
540
{
 
541
  Space *s;
 
542
  s = space_list;
 
543
  while (s != NULL)
 
544
    {
 
545
      if (strcmp(s->name,name)== 0)
 
546
        return s;
 
547
      s = s->next;
 
548
    }
 
549
  PRINT("returning NULL space\n");
 
550
  return NULL;
 
551
}
 
552
 
 
553
 
 
554
 
 
555
 
 
556
/*------------------------------------------------------------------
 
557
                              GetNumberSpaces
 
558
 
 
559
  ------------------------------------------------------------------*/
 
560
int 
 
561
GetNumberSpaces()
 
562
{
 
563
  Space *s;
 
564
  int i;
 
565
 
 
566
  for (i = 0, s = space_list; s != NULL; s = s->next, i++);
 
567
  return i;
 
568
}
 
569
 
 
570
 
 
571
/*------------------------------------------------------------------
 
572
                           GetWorkWindowID
 
573
 
 
574
  ------------------------------------------------------------------*/
 
575
WorkWindow* 
 
576
GetWorkWindowID(Space *s,int wsm_index)
 
577
{
 
578
  int j =0;
 
579
  WorkWindowList *w_list = s->w_list;
 
580
 
 
581
  while (w_list != NULL)
 
582
    {
 
583
      if (_WSMGetConfigFormatType(w_list->work_win->window) == WSM_WINDOW_FMT)
 
584
        {
 
585
          if (j == wsm_index)
 
586
            return w_list->work_win;
 
587
          j++;
 
588
        }
 
589
      w_list = w_list->next;
 
590
    }
 
591
  return NULL;
 
592
}
 
593
 
 
594
 
 
595
 
 
596
 
 
597
/*------------------------------------------------------------------
 
598
                           GetSpaceFromID
 
599
 
 
600
  ------------------------------------------------------------------*/
 
601
Space* 
 
602
GetSpaceFromID(int wsm_index)
 
603
{
 
604
  int j;
 
605
  Space *s;
 
606
  s = space_list;
 
607
  if (s == NULL) return NULL;
 
608
 
 
609
  for (j = 0; j < wsm_index; j++)
 
610
    {
 
611
      if (s == NULL) 
 
612
        return NULL;
 
613
      s = s->next;
 
614
    }
 
615
 return s;
 
616
}
 
617
 
 
618
 
 
619
 
 
620
 
 
621
 
 
622
/*------------------------------------------------------------------
 
623
                           GetSpaceID
 
624
 
 
625
  ------------------------------------------------------------------*/
 
626
int 
 
627
GetSpaceID(Space *space)
 
628
{
 
629
  int j;
 
630
  Space *s;
 
631
 
 
632
  for (j = 0, s = space_list; s != NULL; s = s->next, j++)
 
633
    {
 
634
      if (s == space) 
 
635
        return j;
 
636
    }
 
637
 return -1;
 
638
}
 
639
 
 
640
 
 
641
 
 
642
 
 
643
/*------------------------------------------------------------------
 
644
                           GetWorkWindow
 
645
 
 
646
  ------------------------------------------------------------------*/
 
647
WorkWindow* 
 
648
GetWorkWindow(Window window)
 
649
{
 
650
  WorkWindow *w;
 
651
  w = work_windows;
 
652
  while (w != NULL)
 
653
    {
 
654
      if (w->window == window)
 
655
        return w;
 
656
      w = w->next;
 
657
    }
 
658
  return NULL;
 
659
}
 
660
 
 
661
 
 
662
 
 
663
 
 
664
 
 
665
 
 
666
/*------------------------------------------------------------------
 
667
                           GetWorkWindowClient
 
668
 
 
669
  ------------------------------------------------------------------*/
 
670
/*
 
671
Boolean
 
672
#ifndef _NO_PROTO
 
673
GetWorkWindowClient(Window window, WorkWindow*** w_windows, int *num_w_windows)
 
674
#else
 
675
GetWorkWindowClient(window)
 
676
Window window;
 
677
WorkWindow ***w_windows;
 
678
int *num_w_windows;
 
679
#endif
 
680
{
 
681
  WorkWindow *w, *i_window;
 
682
  int num_w = 0;
 
683
  WorkWindow **w_wins;
 
684
  Boolean found = False;
 
685
 
 
686
  w = work_windows;
 
687
  while (w != NULL)
 
688
    {
 
689
      if (w->window == window)
 
690
        {
 
691
          main_w = w;   
 
692
          found = True;
 
693
          break;
 
694
        }
 
695
      w = w->next;
 
696
    }
 
697
 
 
698
  if (!found) return False;
 
699
 
 
700
  i_window = GetIconWorkWindow(win);
 
701
 
 
702
  if (i_window == NULL)
 
703
    w_wins = (WorkWindow*) XtMalloc(sizeof(WorkWindow*));
 
704
  else
 
705
    w_wins = (WorkWindow*) XtMalloc(2*sizeof(WorkWindow*));
 
706
    
 
707
  w_wins[num_w++] = main_w;
 
708
  if (i_window != NULL)
 
709
    w_wins[num_w++] = i_window;
 
710
 
 
711
  client_id = main_w->specifier_qlist[0];
 
712
  count = main_w->specifier_qlist[2];
 
713
 
 
714
  w = work_windows;
 
715
  while (w != NULL)
 
716
    {   
 
717
      if (w->specifier_qlist[0] == client_id && w->specifier_qlist[2] == count)
 
718
        {
 
719
          w_wins = (WorkWidnow*) XtRealloc(w_wins,(num_w+1) * sizeof(WorkWindow*));
 
720
          w_wins[num_w] = w;
 
721
          num_w++;
 
722
        }
 
723
    }
 
724
 
 
725
  *w_windows = w_wins;
 
726
  *num_w_windows = num_w;
 
727
  return True;
 
728
}
 
729
*/
 
730
 
 
731
 
 
732
 
 
733
 
 
734
 
 
735
/*------------------------------------------------------------------
 
736
                           GetWorkWindowClientIDs
 
737
 
 
738
  ------------------------------------------------------------------*/
 
739
 
 
740
Boolean
 
741
GetWorkWindowClientIDs(int main_pos, Space *s, int **w_ids, int *num_wids)
 
742
{
 
743
  WorkWindowList  *w_list;
 
744
  int num_w = 0;
 
745
  int *wids;
 
746
  Boolean found = False;
 
747
  int pos;
 
748
  WorkWindow *main_w;
 
749
  XrmQuark client_id, count;
 
750
 
 
751
  w_list = s->w_list;
 
752
  pos = 0;
 
753
  while (w_list != NULL)
 
754
    {
 
755
      if (_WSMGetConfigFormatType(w_list->work_win->window) == WSM_WINDOW_FMT)
 
756
        {
 
757
          if (pos == main_pos)
 
758
            {
 
759
              main_w = w_list->work_win;        
 
760
              found = True;
 
761
              break;
 
762
            }
 
763
          pos++;
 
764
        }
 
765
      w_list = w_list->next;
 
766
    }
 
767
 
 
768
  if (!found) return False;
 
769
 
 
770
  wids = (int*) XtMalloc(sizeof(int));
 
771
    
 
772
  wids[num_w++] = main_pos;
 
773
 
 
774
  client_id = main_w->specifier_qlist[0];
 
775
  count = main_w->specifier_qlist[2];
 
776
 
 
777
  w_list = s->w_list;
 
778
  pos = 0;
 
779
  while (w_list != NULL)
 
780
    {   
 
781
      if (_WSMGetConfigFormatType(w_list->work_win->window) == WSM_WINDOW_FMT)
 
782
        {
 
783
          if (w_list->work_win->specifier_qlist[0] == client_id 
 
784
              && w_list->work_win->specifier_qlist[2] == count 
 
785
              && w_list->work_win != main_w)
 
786
            {
 
787
              wids = (int*) XtRealloc((char*)wids,(num_w+1) * sizeof(int));
 
788
              wids[num_w] = pos;
 
789
              num_w++;
 
790
            }
 
791
          pos++;
 
792
        }       
 
793
      w_list = w_list->next;
 
794
    }
 
795
  
 
796
  *w_ids = wids;
 
797
  *num_wids = num_w;
 
798
 
 
799
  return True;
 
800
}
 
801
 
 
802
 
 
803
 
 
804
 
 
805
/*------------------------------------------------------------------
 
806
                           GetIconWorkWindow
 
807
 
 
808
  ------------------------------------------------------------------*/
 
809
WorkWindow* 
 
810
GetIconWorkWindow(Window window)
 
811
{
 
812
  WorkWindow *w;
 
813
  w = work_windows;
 
814
  while (w != NULL)
 
815
    {
 
816
      if (w->window == (window | ~WIN_MASK))
 
817
        return w;
 
818
      w = w->next;
 
819
    }
 
820
  PRINT("returning NULL icon window\n");
 
821
  return NULL;
 
822
}
 
823
 
 
824
 
 
825
/*------------------------------------------------------------------
 
826
                            AddSpaceToWindow
 
827
 
 
828
  ------------------------------------------------------------------*/
 
829
void 
 
830
AddSpaceToWindow(Space *s,
 
831
                 WorkWindow *w_window)
 
832
{
 
833
  SpaceList *s_list, *s_list2;
 
834
 
 
835
  s_list = (SpaceList*)XtMalloc(sizeof(SpaceList));
 
836
  s_list->next = NULL;
 
837
  s_list->space = s;
 
838
  if (w_window->s_list == NULL)
 
839
    {
 
840
      w_window->s_list = s_list;
 
841
    }
 
842
  else 
 
843
    {
 
844
      s_list2 = w_window->s_list;
 
845
      if (s_list2->space == s)
 
846
        {
 
847
          XtFree((char*)s_list);
 
848
          return;
 
849
        }
 
850
      while (s_list2->next != NULL)
 
851
        {
 
852
          s_list2 = s_list2->next;
 
853
          if (s_list2->space == s)
 
854
            {
 
855
              XtFree((char*)s_list);
 
856
              return;
 
857
            }
 
858
        }
 
859
      s_list2->next = s_list;
 
860
    }
 
861
 
 
862
  if ((w_window->s_list != NULL) && (w_window->s_list->next != NULL) &&
 
863
      (w_window->mapped) &&
 
864
      (_WSMGetConfigFormatType(w_window->window) == WSM_WINDOW_FMT))
 
865
  {
 
866
      EnableDeleteCommand(w_window->window);
 
867
  }
 
868
  
 
869
  UpdateButtons(w_window);
 
870
}
 
871
 
 
872
 
 
873
/*------------------------------------------------------------------
 
874
                            AddWindowToSpace
 
875
 
 
876
  ------------------------------------------------------------------*/
 
877
void 
 
878
AddWindowToSpace(Space *s,
 
879
                 WorkWindow *w_window)
 
880
{
 
881
  WorkWindowList *w_list,*w_list2;
 
882
 
 
883
  w_list = (WorkWindowList*)XtMalloc(sizeof(WorkWindowList));
 
884
  w_list->next = NULL;
 
885
  w_list->work_win = w_window;
 
886
  w_list->sib_win = NULL;
 
887
  if (s->w_list == NULL)
 
888
    s->w_list = w_list;
 
889
  else
 
890
    {
 
891
      w_list2 = s->w_list;
 
892
      if (w_list2->work_win == w_window)
 
893
        {
 
894
          XtFree((char*)w_list);
 
895
          return;
 
896
        }
 
897
      while (w_list2->next != NULL)
 
898
        {       
 
899
          w_list2 = w_list2->next;
 
900
          if (w_list2->work_win == w_window)
 
901
            {
 
902
              XtFree((char*)w_list);
 
903
              return;
 
904
            }
 
905
        }       
 
906
      w_list2->next = w_list;
 
907
    }
 
908
  UpdateBothList(s);
 
909
}
 
910
 
 
911
 
 
912
/*------------------------------------------------------------------
 
913
                          RemoveWorkWindowFromSpace
 
914
 
 
915
  ------------------------------------------------------------------*/
 
916
void 
 
917
RemoveWorkWindowFromSpace(Space *s,
 
918
                          WorkWindow *w_window)
 
919
{
 
920
  WorkWindowList *w_list,*pw_list;
 
921
  
 
922
  w_list = s->w_list;
 
923
  pw_list = w_list;
 
924
  while (w_list !=NULL)
 
925
    {
 
926
      if (w_list->work_win == w_window)
 
927
        {
 
928
          if (pw_list == w_list)
 
929
            s->w_list = s->w_list->next;
 
930
          else
 
931
            pw_list->next = w_list->next;
 
932
          XtFree((XtPointer)w_list);
 
933
          UpdateBothList(s);
 
934
          return;
 
935
        }
 
936
      if (w_list->sib_win == w_window)
 
937
        w_list->sib_win = NULL;
 
938
      pw_list = w_list;
 
939
      w_list = w_list->next;
 
940
    }
 
941
  return;
 
942
}
 
943
 
 
944
 
 
945
 
 
946
 
 
947
/*------------------------------------------------------------------
 
948
                            RemoveSpaceFromWindow
 
949
 
 
950
  ------------------------------------------------------------------*/
 
951
void 
 
952
RemoveSpaceFromWindow(Space *s,
 
953
                      WorkWindow *w_window)
 
954
{
 
955
  SpaceList *s_list,*ps_list;
 
956
  
 
957
  s_list = w_window->s_list;
 
958
  ps_list = s_list;
 
959
  while (s_list !=NULL)
 
960
    {
 
961
      if (s_list->space == s)
 
962
        {
 
963
          if (ps_list == s_list)
 
964
            w_window->s_list = w_window->s_list->next;
 
965
          else
 
966
            ps_list->next = s_list->next;
 
967
          XtFree((XtPointer)s_list);
 
968
 
 
969
          if (w_window->s_list != NULL)
 
970
            if (w_window->s_list->next == NULL)
 
971
              DisableDeleteCommand(w_window->window);
 
972
          return;
 
973
        }
 
974
      ps_list = s_list;
 
975
      s_list = s_list->next;
 
976
    }
 
977
  if (w_window->s_list != NULL)
 
978
    if (w_window->s_list->next == NULL)
 
979
      DisableDeleteCommand(w_window->window);
 
980
 
 
981
  UpdateButtons(w_window);
 
982
 
 
983
}
 
984
 
 
985
 
 
986
/*------------------------------------------------------------------
 
987
                          RemoveWorkWindow
 
988
 
 
989
  ------------------------------------------------------------------*/
 
990
void 
 
991
RemoveWorkWindow(WorkWindow *w_window, Boolean purge)
 
992
{
 
993
  SpaceList *s_list;
 
994
  WorkWindow *pre_window, *post_window;
 
995
  pre_window = w_window->prev;
 
996
  post_window = w_window->next;
 
997
  s_list = w_window->s_list;
 
998
  while (s_list != NULL)
 
999
    {
 
1000
      RemoveWorkWindowFromSpace(s_list->space, w_window);
 
1001
      s_list = s_list->next;
 
1002
    }
 
1003
 
 
1004
  if (w_window->all_workspaces) 
 
1005
    RemoveWorkWindowFromSpace(all_space,w_window);
 
1006
 
 
1007
  if (work_windows == w_window)
 
1008
    work_windows = w_window->next;
 
1009
  if (pre_window != NULL)
 
1010
    pre_window->next = post_window;
 
1011
  if (post_window != NULL)
 
1012
    post_window->prev = pre_window;
 
1013
 
 
1014
  if (purge)
 
1015
    (void) PurgeAllWindowConfiguration(shell,
 
1016
                                w_window->specifier_qlist,
 
1017
                                w_window->attrib_qlist);
 
1018
 
 
1019
 
 
1020
  XtFree((XtPointer)w_window->win_data);
 
1021
  XtFree((XtPointer)w_window);
 
1022
}
 
1023
 
 
1024
/*------------------------------------------------------------------
 
1025
                            RemoveSpace
 
1026
 
 
1027
  ------------------------------------------------------------------*/
 
1028
/* not tested */
 
1029
void 
 
1030
RemoveSpace(Space *space)
 
1031
{
 
1032
  WorkWindowList *w_list, *destroy_list;
 
1033
  Space *s, *p;
 
1034
  
 
1035
  w_list = space->w_list;
 
1036
  while (w_list != NULL)
 
1037
    {
 
1038
      RemoveSpaceFromWindow(space,w_list->work_win);
 
1039
      destroy_list = w_list;
 
1040
      w_list = w_list->next;
 
1041
      XtFree((char*)destroy_list);
 
1042
    }
 
1043
 
 
1044
  s = space_list;
 
1045
  p = s;
 
1046
  while (s != NULL)
 
1047
    {
 
1048
      if (s == space)
 
1049
        {
 
1050
          if (p == s)
 
1051
            space_list = s->next;
 
1052
          else
 
1053
            p->next = s->next;
 
1054
        }
 
1055
      p = s;
 
1056
      s = s->next;
 
1057
    }
 
1058
 
 
1059
  XtFree((XtPointer)space);
 
1060
}
 
1061
 
 
1062
/*------------------------------------------------------------------
 
1063
                            IsWorkWindowInSpace
 
1064
 
 
1065
  ------------------------------------------------------------------*/
 
1066
Boolean 
 
1067
IsWorkWindowInSpace(WorkWindow *w,Space *s)
 
1068
{
 
1069
  WorkWindowList *w_list;
 
1070
 
 
1071
  if (w->all_workspaces && s!= all_space) return True;
 
1072
  w_list = s->w_list;
 
1073
  while (w_list != NULL)
 
1074
    {
 
1075
      if (w_list->work_win == w)
 
1076
        return True;
 
1077
      w_list = w_list->next;
 
1078
    }
 
1079
  return False;
 
1080
}
 
1081
 
 
1082
 
 
1083
/*------------------------------------------------------------------
 
1084
                           IsSpaceInWorkWindow
 
1085
 
 
1086
  ------------------------------------------------------------------*/
 
1087
Boolean 
 
1088
IsSpaceInWorkWindow(Space *s, WorkWindow *w)
 
1089
{
 
1090
  SpaceList *s_list;
 
1091
 
 
1092
  if (w->all_workspaces && s!= all_space) return True;
 
1093
  s_list = w->s_list;
 
1094
  while (s_list !=NULL)
 
1095
    {
 
1096
      if (s_list->space == s)
 
1097
        return True;
 
1098
      s_list = s_list->next;
 
1099
    }
 
1100
  return False;
 
1101
}
 
1102
 
 
1103
 
 
1104
/*------------------------------------------------------------------
 
1105
                            InitializeWsm
 
1106
 
 
1107
  ------------------------------------------------------------------*/
 
1108
void InitializeWsm()
 
1109
{
 
1110
  atoms.save_property = XmInternAtom(XtDisplay(shell),"WM_SAVE_YOURSELF",False);
 
1111
  atoms.protocols_property = XmInternAtom(XtDisplay(shell),"WM_PROTOCOLS",False);
 
1112
  atoms.sm_client_id_property = XmInternAtom(XtDisplay(shell),"_MOTIF_SM_CLIENT_ID",False);
 
1113
  atoms.wm_role_property = XmInternAtom(XtDisplay(shell),"_MOTIF_WM_WINDOW_ROLE",False);
 
1114
  atoms.wm_client_leader = XmInternAtom(XtDisplay(shell),"WM_CLIENT_LEADER",False);
 
1115
  
 
1116
  all_space = (Space *)XtMalloc(sizeof(Space));
 
1117
  all_space->nameq = XrmStringToQuark("all");
 
1118
  all_space->w_list = NULL;
 
1119
  all_space->next = NULL;
 
1120
  
 
1121
  current_space = NULL;
 
1122
}
 
1123
 
 
1124
 
 
1125
 
 
1126
/*------------------------------------------------------------------
 
1127
                            RestartWsm
 
1128
 
 
1129
  ------------------------------------------------------------------*/
 
1130
 
 
1131
void CompleteRestartWSM()
 
1132
{
 
1133
  Space *s;
 
1134
  WorkWindowList *w_list, *destroy_w_list;
 
1135
  WorkWindow *w, *destroy_w;
 
1136
  SpaceList *s_list, *destroy_s_list;
 
1137
 
 
1138
  s = space_list;
 
1139
 
 
1140
  while (s!= NULL)
 
1141
    {
 
1142
      w_list = s->w_list;
 
1143
      while (w_list != NULL)
 
1144
        {
 
1145
          destroy_w_list = w_list;
 
1146
          w_list = w_list->next;
 
1147
          XtFree((XtPointer)destroy_w_list);
 
1148
        }
 
1149
      s->w_list = NULL;
 
1150
      s = s->next;
 
1151
    }
 
1152
  
 
1153
  w_list = all_space->w_list;
 
1154
  while (w_list != NULL)
 
1155
    {   
 
1156
      destroy_w_list=w_list;
 
1157
      w_list = w_list->next;
 
1158
      XtFree((XtPointer)destroy_w_list);
 
1159
    }
 
1160
 
 
1161
  all_space->w_list = NULL;
 
1162
  all_space->next = NULL;
 
1163
 
 
1164
  w = work_windows;
 
1165
  while (w!= NULL)
 
1166
    {
 
1167
      destroy_w = w;
 
1168
      s_list = w->s_list;
 
1169
      while (s_list != NULL)
 
1170
        {
 
1171
          destroy_s_list = s_list;
 
1172
          s_list = s_list->next;
 
1173
          XtFree((XtPointer)destroy_s_list);
 
1174
        }
 
1175
      w = w->next;
 
1176
      XtFree((XtPointer)destroy_w);
 
1177
    }
 
1178
 
 
1179
  work_windows = NULL;
 
1180
 
 
1181
  PRINT("Restarting WSM\n");
 
1182
 
 
1183
}
 
1184
 
 
1185
 
 
1186
void RestartWSM()
 
1187
{
 
1188
  WorkWindow *w;
 
1189
 
 
1190
  for (w = work_windows; w != NULL; w = w->next)
 
1191
  {
 
1192
      w->used = False;
 
1193
  }
 
1194
}
 
1195
 
 
1196
void FinishRestartWSM()
 
1197
{
 
1198
  WorkWindow *w;
 
1199
 
 
1200
  for (w = work_windows; w != NULL; w = w->next)
 
1201
  {
 
1202
      if (w->used == False)
 
1203
      {
 
1204
          RemoveWorkWindow(w,False);
 
1205
      }
 
1206
  }
 
1207
}
 
1208
/*------------------------------------------------------------------
 
1209
                            GetWSMWindow
 
1210
 
 
1211
  ------------------------------------------------------------------*/
 
1212
Window
 
1213
GetWSMWindow(WorkWindow *w_window)
 
1214
{
 
1215
 
 
1216
  return (w_window->window);
 
1217
   
 
1218
}
 
1219
 
 
1220
 
 
1221
 
 
1222
/*------------------------------------------------------------------
 
1223
                            SetWorkWindowValues
 
1224
 
 
1225
  ------------------------------------------------------------------*/
 
1226
void 
 
1227
SetWorkWindowValues(WorkWindow *w, Boolean all_workspaces, Boolean linked)
 
1228
{
 
1229
  if (all_workspaces && !(w->all_workspaces))
 
1230
      {
 
1231
        AddWindowToSpace(all_space,w);  
 
1232
        UpdateBothList(all_space);
 
1233
        UpdateButtons(w);
 
1234
      }
 
1235
  else if (!all_workspaces && w->all_workspaces)
 
1236
    {
 
1237
      RemoveWorkWindowFromSpace(all_space,w);
 
1238
      UpdateBothList(all_space);
 
1239
      UpdateButtons(w);
 
1240
    }
 
1241
  w->all_workspaces = all_workspaces;
 
1242
  w->linked = linked;
 
1243
 
 
1244
      
 
1245
}
 
1246
 
 
1247
 
 
1248
/*------------------------------------------------------------------
 
1249
                            UnmapCurrentSpace
 
1250
 
 
1251
  ------------------------------------------------------------------*/
 
1252
void 
 
1253
UnmapCurrentSpace()
 
1254
{
 
1255
  WorkWindowList *w_list = current_space->w_list;
 
1256
  while (w_list!= NULL)
 
1257
    {
 
1258
      w_list->work_win->mapped = False;
 
1259
      w_list = w_list->next;
 
1260
    }
 
1261
}
 
1262
 
 
1263
/*------------------------------------------------------------------
 
1264
                            UnmapWorkWindow
 
1265
 
 
1266
  ------------------------------------------------------------------*/
 
1267
void 
 
1268
UnmapWorkWindow(WorkWindow *w_window)
 
1269
{
 
1270
  w_window->mapped = False;
 
1271
}
 
1272
 
 
1273
/*------------------------------------------------------------------
 
1274
                            MapWorkWindow
 
1275
 
 
1276
  ------------------------------------------------------------------*/
 
1277
void 
 
1278
MapWorkWindow(WorkWindow *w_window)
 
1279
{
 
1280
  w_window->mapped = True;
 
1281
}
 
1282
 
 
1283
 
 
1284
/**********************************************************************/
 
1285
/*  This is for testing purposes.                                     */
 
1286
/**********************************************************************/
 
1287
 
 
1288
 
 
1289
char*
 
1290
trimblanks(char *s)
 
1291
{
 
1292
  char    *p;
 
1293
 
 
1294
  p = &s[strlen(s)-1];    /* point to last char */
 
1295
  while((*p <= ' ') && p >= s) p--;
 
1296
  p++;
 
1297
  *p = '\0';
 
1298
 
 
1299
  return s;
 
1300
}
 
1301
 
 
1302
 
 
1303
void
 
1304
translate_for_database(char *s)
 
1305
{
 
1306
  int length = strlen(s);
 
1307
  int i,j;
 
1308
 
 
1309
 
 
1310
  for (i = 0; i < length; i++)
 
1311
    {
 
1312
      if (s[i] == ':')
 
1313
        {
 
1314
          s[i] = '&';
 
1315
        }
 
1316
    }
 
1317
}
 
1318
 
 
1319
static char* 
 
1320
GetWMName(Window window, Boolean is_icon)
 
1321
{
 
1322
  XTextProperty   textProperty;
 
1323
  char *str;
 
1324
 
 
1325
  if (window == 0) 
 
1326
    {
 
1327
      str = (char*) XtMalloc((strlen("Global") +1) * sizeof(char));     
 
1328
      strcpy(str,"Global");
 
1329
      return str;
 
1330
    }
 
1331
  if(XGetWMName(dsp, (window & WIN_MASK), &textProperty)) {
 
1332
    if (textProperty.encoding == XA_STRING) {
 
1333
      if (textProperty.value) {
 
1334
        str = (String)textProperty.value;
 
1335
        trimblanks(str);
 
1336
        if(str[0]) 
 
1337
          {
 
1338
            if (is_icon)
 
1339
              {
 
1340
                str = (char*)XtRealloc(str,(strlen(str)+2 )* sizeof(char));
 
1341
                strcat(str,"I");
 
1342
              }
 
1343
            return str;
 
1344
          }
 
1345
      }
 
1346
    }
 
1347
  }
 
1348
  
 
1349
  strcpy(str, "");
 
1350
  return str;
 
1351
}
 
1352
 
 
1353
 
 
1354
 
 
1355
 
 
1356
static char * 
 
1357
GetWMClient(Window window, Boolean is_icon)
 
1358
{
 
1359
  int format;
 
1360
  int status;
 
1361
  unsigned long nitems, after;
 
1362
  Atom type = None;
 
1363
  char *str;
 
1364
 
 
1365
  status = XGetWindowProperty(dsp, 
 
1366
                              (window & WIN_MASK), 
 
1367
                              atoms.sm_client_id_property,
 
1368
                              0L,(long)1000,
 
1369
                              False,    
 
1370
                              XA_STRING,
 
1371
                              &type,
 
1372
                              &format,
 
1373
                              &nitems,
 
1374
                              &after,
 
1375
                              (unsigned char **)&str);
 
1376
  
 
1377
  if (status == Success)
 
1378
    {
 
1379
      if (str == NULL) return (NULL);
 
1380
      translate_for_database(str);
 
1381
      if (is_icon)
 
1382
        {
 
1383
          str = (char*) XtRealloc((char*)str,(strlen(str)+2) * sizeof(char));
 
1384
          strcat(str,"I");
 
1385
        }
 
1386
      return str;
 
1387
    }
 
1388
 
 
1389
 
 
1390
  /*
 
1391
   * if there's no clientID on this window, then see if it points
 
1392
   * to a client leader that has a clientID.
 
1393
   */
 
1394
  else
 
1395
    {
 
1396
      Window leader;
 
1397
 
 
1398
      /* check for CLIENT_LEADER property. */
 
1399
      status = XGetWindowProperty(dsp, 
 
1400
                                  (window & WIN_MASK), 
 
1401
                                  atoms.wm_client_leader,
 
1402
                                  0L,(long)1000,
 
1403
                                  False,
 
1404
                                  XA_WINDOW,
 
1405
                                  &type,
 
1406
                                  &format,
 
1407
                                  &nitems,
 
1408
                                  &after,
 
1409
                                  (unsigned char **)&leader);
 
1410
      if (status == Success)
 
1411
        {
 
1412
          if ((leader == None) || (leader == window))
 
1413
            return (NULL);
 
1414
          else
 
1415
            return (GetWMClient(leader, is_icon));
 
1416
        }
 
1417
 
 
1418
      else
 
1419
        {
 
1420
          /* Old-style client - no WM_CLIENT_ID property */
 
1421
          return (NULL);
 
1422
        }
 
1423
    }
 
1424
}
 
1425
 
 
1426
 
 
1427
 
 
1428
 
 
1429
 
 
1430
static 
 
1431
char * 
 
1432
GetWMRole(Window window, Boolean is_icon)
 
1433
{
 
1434
  int format;
 
1435
  int status;
 
1436
  unsigned long nitems, after;
 
1437
  Atom type = None;
 
1438
  char *str;
 
1439
 
 
1440
  status = XGetWindowProperty(dsp, 
 
1441
                              (window & WIN_MASK), 
 
1442
                              atoms.wm_role_property,
 
1443
                              0L,(long)1000,
 
1444
                              False,    
 
1445
                              XA_STRING,
 
1446
                              &type,
 
1447
                              &format,
 
1448
                              &nitems,
 
1449
                              &after,
 
1450
                              (unsigned char **)&str);
 
1451
 
 
1452
  if (status == Success)
 
1453
    {
 
1454
      if (str == NULL) return (NULL);
 
1455
      translate_for_database(str);
 
1456
      if (is_icon)
 
1457
        {
 
1458
          str = (char*) XtRealloc((char*)str,(strlen(str)+2) * sizeof(char));
 
1459
          strcat(str,"I");
 
1460
        }
 
1461
      return str;
 
1462
    }
 
1463
 
 
1464
  else return (NULL);
 
1465
}
 
1466
 
 
1467
 
 
1468
 
 
1469
 
 
1470
 
 
1471
static
 
1472
char *
 
1473
GetWMCount(XrmQuark client, XrmQuark role)
 
1474
{
 
1475
  WorkWindow *w;
 
1476
  char *str;
 
1477
  int count;
 
1478
  
 
1479
  count = 0;
 
1480
  for (w = work_windows; w!= NULL; w = w->next)
 
1481
    {
 
1482
      if (w->specifier_qlist[0] == client && w->specifier_qlist[1] == role)
 
1483
        count++;
 
1484
    }
 
1485
  str = (String) XtMalloc(4*sizeof(char));
 
1486
/*  if (count == 0)
 
1487
    strcpy(str,"*");
 
1488
  else*/
 
1489
    sprintf(str,"%d",count);
 
1490
  return str;
 
1491
}
 
1492
 
 
1493
 
 
1494
XrmQuarkList 
 
1495
GetSpecifierQList(Window window, Boolean is_icon)
 
1496
{
 
1497
  XrmQuark *specifier;
 
1498
  char *client;
 
1499
  char *role;
 
1500
  char *count;
 
1501
 
 
1502
  specifier = (XrmQuark*)XtMalloc(4*sizeof(XrmQuark));
 
1503
 
 
1504
  if (window != 0)
 
1505
    {
 
1506
      client = GetWMClient(window, is_icon);
 
1507
      if (client == NULL)
 
1508
        client = GetWMName(window,is_icon);
 
1509
      role = GetWMRole(window, is_icon);
 
1510
      if (role == NULL)
 
1511
        role = GetWMName(window,is_icon);
 
1512
      specifier[0] = XrmStringToQuark(client);
 
1513
      specifier[1] = XrmStringToQuark(role);
 
1514
      count = GetWMCount(specifier[0],specifier[1]);
 
1515
      specifier[2] = XrmStringToQuark(count);
 
1516
      specifier[3] = NULLQUARK;
 
1517
      XtFree((XtPointer)client);
 
1518
      XtFree((XtPointer)role);
 
1519
      XtFree((XtPointer)count);
 
1520
    }
 
1521
  else
 
1522
    {
 
1523
      specifier[0] = XrmStringToQuark("Global");
 
1524
      specifier[1] = NULLQUARK;
 
1525
    }
 
1526
  return specifier;
 
1527
}
 
1528
 
 
1529