1 /*
2  * Motif
3  *
4  * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  * HISTORY
25  */
26 #ifdef REV_INFO
27 #ifndef lint
28 static char rcsid[] = "$TOG: command_ui.c /main/8 1997/05/02 10:08:26 dbl $"
29 #endif
30 #endif
31 
32 #include <stdlib.h>
33 #include <Xm/Xm.h>
34 #include <Xm/ToggleB.h>
35 #include <X11/Xmd.h>
36 
37 #include "Wsm/wsm_proto.h"
38 #include "Wsm/wsm_funcs.h"
39 #include "Wsm/utm_send.h"
40 #include "wsm.h"
41 #include "wsmStruct.h"
42 #include "wsmDebug.h"
43 #include "command_ui.h"
44 #include "wsm_cb.h"
45 #include "wsm_ui.h"
46 
47 extern AtomStruct atoms;
48 extern Display *dsp;
49 extern Widget shell;
50 extern Widget shell_ui;
51 extern Space* space_list;
52 extern Space* all_space;
53 extern Space *current_space;
54 extern WSM_UI* wsm_ui;
55 
56 extern Boolean wsm_shown;
57 
58 int debug_index = 0;
59 
60 #define GET_COMMAND_ID(dpy) ((CARD32) XAllocID(dpy))
61 
62 CARD32 switch_id;
63 CARD32 show_id;
64 CARD32 occupy_id;
65 CARD32 copy_all_id;
66 CARD32 link_all_id;
67 CARD32 remove_id;
68 
69 Boolean exiting = False;
70 CommandSpace *command_space_list;
71 typedef enum {ROOT, ALL, ICON, WIN, DEFINE, INCLUDE, REMOVE,
72 	      ENABLE, DISABLE, RENAME, INLINE, MAXTOGGLES } RType;
73 
74 Atom WM_S0,
75      _MOTIF_WM_DEFINE_COMMAND,
76      _MOTIF_WM_INCLUDE_COMMAND,
77      _MOTIF_WM_DISABLE_COMMAND,
78      _MOTIF_WM_ENABLE_COMMAND,
79      _MOTIF_WM_INVOKE_COMMAND,
80      _MOTIF_WM_REMOVE_COMMAND,
81      _MOTIF_WM_RENAME_COMMAND;
82 
83 Time
GetTimestamp(Display * dpy)84 GetTimestamp (Display *dpy)
85 {
86   XEvent   event;
87   XWindowAttributes attr;
88   Window   rwin = RootWindowOfScreen(XtScreen(utmShell));
89   Atom     time_atom = XInternAtom(dsp, "_MOTIF_CURRENT_TIME", False);
90 
91   XGetWindowAttributes(dsp, rwin, &attr);
92   if (! (attr.your_event_mask & PropertyChangeMask))
93     XSelectInput(dsp, rwin, attr.your_event_mask | PropertyChangeMask);
94 
95   XChangeProperty(dsp, rwin, time_atom, time_atom, 8, PropModeAppend, NULL, 0);
96   XWindowEvent(dsp, rwin, PropertyChangeMask, &event);
97 
98   if (! (attr.your_event_mask & PropertyChangeMask))
99     XSelectInput(dsp, rwin, attr.your_event_mask);
100 
101   return(event.xproperty.time);
102 }
103 
104 
105 /*----------------------------------------------------------------------*
106  |                              SelectionProc                           |
107  | This is invoked when a message is finished and the reply is received.|
108  *----------------------------------------------------------------------*/
109 void
SelectionProc(Widget w,XtPointer clientData,XtPointer callData)110 SelectionProc (Widget w, XtPointer clientData, XtPointer callData)
111 {
112 
113 }
114 
115 
116 
117 
118 /*----------------------------------------------------------------------*
119  |                              LastSelectionProc                       |
120  | This is invoked when the last message is finished and the reply is   |
121  | received.                                                            |
122  *----------------------------------------------------------------------*/
123 void
LastSelectionProc(Widget w,XtPointer clientData,XtPointer callData)124 LastSelectionProc (Widget w, XtPointer clientData, XtPointer callData)
125 {
126     Display *dsp = XtDisplay(w);
127 
128     XSync(dsp, False);
129     XCloseDisplay(dsp);
130 
131     exit(0);
132 }
133 
134 
135 
136 /*----------------------------------------------------------------------*
137  |                             SendMessage                              |
138  *----------------------------------------------------------------------*/
139 void
SendMessage(RType rtype,XtPointer msg,int len,Time time)140 SendMessage(RType rtype, XtPointer msg, int len, Time time)
141 {
142   XtCallbackProc s_proc;
143   Atom target = 0;
144 
145   if (!exiting) s_proc = SelectionProc;
146   else s_proc = LastSelectionProc;
147   if (!XtIsRealized(shell))
148     {
149       PRINT("must be realized\n");
150       return;
151     }
152   switch (rtype)
153     {
154     case DEFINE:
155       target = _MOTIF_WM_DEFINE_COMMAND;
156       break;
157     case INCLUDE:
158       target = _MOTIF_WM_INCLUDE_COMMAND;
159       break;
160     case REMOVE:
161       target = _MOTIF_WM_REMOVE_COMMAND;
162       break;
163     case ENABLE:
164       target = _MOTIF_WM_ENABLE_COMMAND;
165       break;
166     case DISABLE:
167       target = _MOTIF_WM_DISABLE_COMMAND;
168       break;
169     case RENAME:
170       target = _MOTIF_WM_RENAME_COMMAND;
171       break;
172     case ROOT:
173     case ALL:
174     case ICON:
175     case WIN:
176     case INLINE:
177     case MAXTOGGLES:
178       /* Not handled cases */
179       break;
180     }
181 
182   UTMSendMessage(utmShell, WM_S0, target,
183 		 (XtPointer) msg, (unsigned long)len, WSM_PROTO_FMT,
184 		 s_proc, (XtPointer)++debug_index, time);
185 
186   if (msg != NULL)
187     XtFree(msg);
188 }
189 
190 /*----------------------------------------------------------------------*
191  |                                SendEnable                            |
192  *----------------------------------------------------------------------*/
193 void
SendEnableCommand(Window window,CARD32 commandID)194 SendEnableCommand (Window window, CARD32 commandID)
195 {
196 #ifndef _NO_DISABLE
197   Time    time;
198   XtPointer msg,save;
199   int     size=0;
200   CARD32  count = 1L;
201   CARD32  windowBit = 1<<30;
202 /*  CARD32  iconBit = 1<<31;*/
203   char   str[128];
204 
205   time = GetTimestamp(dsp);
206 
207   size += sizeof(CARD32);  /* command id */
208   size += sizeof(CARD32);  /* count */
209   size += sizeof(CARD32);  /* window */
210 
211   save = msg = (XtPointer) XtMalloc(size);
212 
213   window |= windowBit;
214 
215   msg = PackCARD32(msg,(CARD32)commandID);
216   msg = PackCARD32(msg,(CARD32)count);
217   msg = PackCARD32(msg,(CARD32)window);
218 
219   PRINT("EnableCommand #%d on window %x (%u).\n",
220 	  commandID, window, window);
221 
222   SendMessage(ENABLE, save, size, time);
223 
224 #endif
225 }
226 
227 
228 
229 /*----------------------------------------------------------------------*
230  |                                 SendDisable                            |
231  *----------------------------------------------------------------------*/
232 void
SendDisableCommand(Window window,CARD32 commandID)233 SendDisableCommand (Window window, CARD32 commandID)
234 {
235 #ifndef _NO_DISABLE
236  Time    time;
237   XtPointer msg,save;
238   int     size=0;
239   CARD32  count = 1L;
240   CARD32  windowBit = 1<<30;
241 /*  CARD32  iconBit = 1<<31;*/
242   char   str[128];
243 
244   time = GetTimestamp(dsp);
245 
246   size += sizeof(CARD32);  /* command id */
247   size += sizeof(CARD32);  /* count */
248   size += sizeof(CARD32);  /* window */
249 
250   save = msg = (XtPointer) XtMalloc(size);
251 
252   window |= windowBit;
253 
254   msg = PackCARD32(msg,(CARD32)commandID);
255   msg = PackCARD32(msg,(CARD32)count);
256   msg = PackCARD32(msg,(CARD32)window);
257 
258   PRINT("DisableCommand #%d on window %x (%u).\n",
259 	  commandID, window, window);
260 
261   SendMessage(DISABLE, save, size, time);
262 #endif
263 }
264 
265 
266 
267 /*----------------------------------------------------------------------*
268  |                                 SendInclude                           |
269  *----------------------------------------------------------------------*/
270 void
SendIncludeCommand(Window window,int commID,Boolean is_in_line)271 SendIncludeCommand(Window window, int commID, Boolean is_in_line)
272 {
273   Time time;
274   XtPointer msg, save;
275   CARD32  commandID = 0L;
276   CARD32  in_line = 0L;
277   CARD32  selection = 0L;
278   CARD32  count = 1L;
279   CARD32  windowBit = 1<<30;
280 /*  CARD32  iconBit = 1<<31;*/
281   char   str[128];
282   int     size=0;
283 
284   commandID += commID;
285   selection += atoms.own_selection;
286   if (is_in_line)
287     {
288       in_line = 1L;
289     }
290   time = GetTimestamp(dsp);
291   /*
292    *  Fixup the window id receiving the client command.
293    *  Top 2 bits:
294    *  	10 - Icon only
295    *	01 - Window only
296    *	11 - Both Icon and Window
297    *	00 - Reserved (Don't Use!)
298    *
299    *  Bottom 30 bits:
300    *	0x3fffffff - All windows and/or icons
301    *	0x00000000 - Root window menu
302    */
303 
304   size += sizeof(CARD32);  /* in-line*/
305   size += sizeof(CARD32);  /* command id */
306   size += sizeof(CARD32);  /* selection */
307   size += sizeof(CARD32);  /* count */
308   size += sizeof(CARD32);  /* window */
309 
310   save = msg = (XtPointer) XtMalloc(size);
311 
312   window |= windowBit;
313 
314   msg = PackCARD32(msg, (CARD32)in_line);
315   msg = PackCARD32(msg, (CARD32)commandID);
316   msg = PackCARD32(msg, (CARD32)selection);
317   msg = PackCARD32(msg, (CARD32)count);
318   msg = PackCARD32(msg, (CARD32)window);
319 
320   PRINT("IncludeCommand #%d on window %x (%u).\n", commandID, window, window);
321 
322   SendMessage(INCLUDE, save, size, time);
323 }
324 
325 
326 
327 /*----------------------------------------------------------------------*
328  |                                 SendRemove                         |
329  *----------------------------------------------------------------------*/
330 void
SendRemoveCommand(Window window,CARD32 commandID)331 SendRemoveCommand(Window window, CARD32 commandID)
332 {
333   Time time;
334   XtPointer msg,save;
335   CARD32  selection = 0L;
336   CARD32  count = 1L;
337   CARD32  windowBit = 1<<30;
338 /*  CARD32  iconBit = 1<<31;*/
339   char   str[128];
340   int     size=0;
341 
342   time = GetTimestamp(dsp);
343 
344   selection += atoms.own_selection;
345   /*
346    *  Fixup the window id receiving the client command.
347    *  Top 2 bits:
348    *  	10 - Icon only
349    *	01 - Window only
350    *	11 - Both Icon and Window
351    *	00 - Reserved (Don't Use!)
352    *
353    *  Bottom 30 bits:
354    *	0x3fffffff - All windows and/or icons
355    *	0x00000000 - Root window menu
356    */
357 
358   window |= windowBit;
359 
360   size += sizeof(CARD32);  /* command id */
361   size += sizeof(CARD32);  /* count */
362   size += sizeof(CARD32);  /* window id */
363 
364 
365   save = msg = (XtPointer) XtMalloc(size);
366 
367   msg = PackCARD32(msg, (CARD32) commandID);
368   msg = PackCARD32(msg, (CARD32) count);
369   msg = PackCARD32(msg, (CARD32) window);
370 
371   PRINT("RemoveCommand #%d on window %x (%u).\n", commandID, window, window);
372 
373   SendMessage(REMOVE, save, size, time);
374 }
375 
376 
377 /*----------------------------------------------------------------------*
378   |                                 SendDefineCommand                     |
379  *----------------------------------------------------------------------*/
380 void
SendDefineCommand(int parID,int commID,char * cmdName,char * cmdDefault)381 SendDefineCommand (int parID, int commID, char *cmdName, char *cmdDefault)
382 {
383   Time    time;
384   XtPointer msg,save;
385   int     size=0;
386   CARD32  selection = 0L;
387   CARD32 commandID = 0L;
388   CARD32 parentID = 0L;
389 
390   commandID += commID;
391   parentID += parID;
392   time = GetTimestamp(dsp);
393 
394   selection += atoms.own_selection;
395   size += sizeof(CARD32);  /* command id */
396   size += sizeof(CARD32); /* selection */
397   size += sizeof(CARD32);  /* parent id */
398   size += sizeof(CARD16) + (strlen(cmdName) * sizeof(CARD8)); /* name */
399   size += sizeof(CARD16) + (strlen(cmdDefault) * sizeof(CARD8)); /* defalault label */
400 
401   save = msg = (XtPointer) XtMalloc(size);
402 
403 
404   msg = PackCARD32(msg, (CARD32) commandID);
405   msg = PackCARD32(msg, (CARD32) selection);
406   msg = PackCARD32(msg, (CARD32) parentID);
407   msg = PackString(msg, (String) cmdName);
408   msg = PackString(msg, (String) cmdDefault);
409 
410   PRINT("DefineCommand: %d, %d, %d, '%s', '%s'\n",
411 	 commandID, selection, parentID, cmdName, cmdDefault);
412   SendMessage(DEFINE, save, size, time);
413 
414 
415 }
416 
417 
418 /*----------------------------------------------------------------------*
419  |                                 SendRename                           |
420  *----------------------------------------------------------------------*/
421 void
SendRenameCommand(Window window,int commID,char * new_name)422 SendRenameCommand(Window window, int commID, char *new_name)
423 {
424   Time time;
425   XtPointer msg, save;
426   CARD32  commandID = 0L;
427   CARD32  count = 1L;
428   CARD32  windowBit = 1<<30;
429 /*  CARD32  iconBit = 1<<31;*/
430   char   str[128];
431   int     size=0;
432 
433   commandID += commID;
434 
435   time = GetTimestamp(dsp);
436   /*
437    *  Fixup the window id receiving the client command.
438    *  Top 2 bits:
439    *  	10 - Icon only
440    *	01 - Window only
441    *	11 - Both Icon and Window
442    *	00 - Reserved (Don't Use!)
443    *
444    *  Bottom 30 bits:
445    *	0x3fffffff - All windows and/or icons
446    *	0x00000000 - Root window menu
447    */
448 
449   size += sizeof(CARD32);  /* command id */
450   size += sizeof(CARD16) + (strlen(new_name) * sizeof(CARD8));
451   size += sizeof(CARD32);  /* count */
452   size += sizeof(CARD32);  /* window */
453 
454   save = msg = (XtPointer) XtMalloc(size);
455 
456   window |= windowBit;
457 
458   msg = PackCARD32(msg, (CARD32)commandID);
459   msg = PackString(msg, (String) new_name);
460   msg = PackCARD32(msg, (CARD32)count);
461   msg = PackCARD32(msg, (CARD32)window);
462 
463   PRINT("RenameCommand #%d to %s on window %x (%u).\n", commandID,
464 	new_name, window, window);
465 
466   SendMessage(RENAME, save, size, time);
467 }
468 
469 
470 
471 /*----------------------------------------------------------------------*
472   |                               CS Structure stuff                    |
473  *----------------------------------------------------------------------*/
474 CommandSpace *
GetCSFromCopyID(CARD32 i)475 GetCSFromCopyID(CARD32 i)
476 {
477   CommandSpace *cs;
478   cs = command_space_list;
479   while (cs != NULL)
480     {
481       if (cs->copy_command_id == i)
482 	{
483 	  return cs;
484 	}
485       cs = cs->next;
486     }
487   return NULL;
488 }
489 
490 
491 
492 
493 
494 CommandSpace *
GetCSFromLinkID(CARD32 i)495 GetCSFromLinkID(CARD32 i)
496 {
497   CommandSpace *cs;
498   cs = command_space_list;
499   while (cs != NULL)
500     {
501       if (cs->link_command_id == i)
502 	{
503 	  return cs;
504 	}
505       cs = cs->next;
506     }
507   return NULL;
508 }
509 
510 
511 
512 CommandSpace *
GetCSFromSwitchID(CARD32 i)513 GetCSFromSwitchID(CARD32 i)
514 {
515   CommandSpace *cs;
516   cs = command_space_list;
517   while (cs != NULL)
518     {
519       if (cs->switch_command_id == i)
520 	return cs;
521       cs = cs->next;
522     }
523   PRINT("GetCSFromSwitch(%d) returning NULL\n",i);
524   return NULL;
525 }
526 
527 
528 
529 CommandSpace *
GetCSFromSpaceID(int i)530 GetCSFromSpaceID(int i)
531 {
532   int j;
533   CommandSpace *cs;
534   cs = command_space_list;
535   if (cs == NULL) return NULL;
536 
537   for (j = 0; j < i; j++)
538     {
539       if (cs == NULL)
540 	return NULL;
541       cs = cs->next;
542     }
543   return cs;
544 }
545 
546 
547 
548 CommandSpace *
GetCSFromSpace(Space * space)549 GetCSFromSpace(Space *space)
550 {
551   CommandSpace *cs;
552   cs = command_space_list;
553   while (cs != NULL)
554     {
555       if (cs->space == space)
556 	return cs;
557       cs = cs->next;
558     }
559   return NULL;
560 }
561 
562 Space *
GetSpaceFromLinkID(CARD32 c_id)563 GetSpaceFromLinkID(CARD32 c_id)
564 {
565   CommandSpace *cs = command_space_list;
566   while (cs != NULL)
567     {
568       if (cs->link_command_id == c_id)
569 	return cs->space;
570       cs = cs->next;
571     }
572   return NULL;
573 }
574 
575 
576 
577 
578 Space *
GetSpaceFromCopyID(CARD32 c_id)579 GetSpaceFromCopyID(CARD32 c_id)
580 {
581   CommandSpace *cs = command_space_list;
582   while (cs != NULL)
583     {
584       if (cs->copy_command_id == c_id)
585 	return cs->space;
586       cs = cs->next;
587     }
588   return NULL;
589 }
590 
591 
592 
593 Space *
GetSpaceFromSwitchID(CARD32 c_id)594 GetSpaceFromSwitchID(CARD32 c_id)
595 {
596   CommandSpace *cs = command_space_list;
597   while (cs != NULL)
598     {
599       if (cs->switch_command_id == c_id)
600 	return cs->space;
601       cs = cs->next;
602     }
603   return NULL;
604 }
605 
606 void
RemoveCommandSpace(CommandSpace * cspace)607 RemoveCommandSpace(CommandSpace *cspace)
608 {
609   CommandSpace *cs = command_space_list;
610   CommandSpace *pcs = command_space_list;
611 
612   while (cs != NULL)
613     {
614       if (cs == cspace)
615 	{
616 	  if (cs == pcs)
617 	    command_space_list = cs->next;
618 	  else
619 	    pcs->next = cs->next;
620 	}
621       pcs = cs;
622       cs = cs->next;
623     }
624 
625   XtFree((XtPointer)cspace);
626 }
627 
628 
629 
630 
631 CommandSpace*
CreateCommandSpace(Space * space,CARD32 copy_id,CARD32 link_id,CARD32 switch_id)632 CreateCommandSpace(Space *space,CARD32 copy_id, CARD32 link_id,CARD32 switch_id)
633 {
634   CommandSpace *s, *s2;
635   s = (CommandSpace*)XtMalloc(sizeof(CommandSpace));
636   s->space = space;
637   s->copy_command_id = copy_id;
638   s->link_command_id = link_id;
639   s->switch_command_id = switch_id;
640   s->next = NULL;
641 
642   if (command_space_list == NULL)
643     command_space_list = s;
644   else
645     {
646       for (s2 = command_space_list; s2->next != NULL; s2 = s2->next);
647       s2->next = s;
648     }
649   return s;
650 }
651 
652 
653 /*----------------------------------------------------------------------*
654  |                                InvokeCommand                      |
655  *----------------------------------------------------------------------*/
656 void
InvokeCommand(Widget w,Atom target,MessageData data,unsigned long len,int fmt)657 InvokeCommand (
658      Widget         w,
659      Atom           target,
660      MessageData    data,
661      unsigned long  len,
662      int            fmt)
663 {
664   CARD32      	commandID;
665   Window  	windowID;
666   WorkWindow *w_window;
667   CommandSpace *cs;
668   commandID = UnpackCARD32(&data);
669   windowID = UnpackCARD32(&data);
670 
671 
672   PRINT("commandID = %d\n",commandID);
673   PRINT("windowID = %d\n", windowID);
674 
675   if (commandID == show_id)
676   {
677       if (wsm_shown)
678       {
679 	  PRINT("hide workspace manager\n");
680 	  HideWsm();
681       }
682       else
683       {
684 	  PRINT("show workspace manager\n");
685 	  ShowWsm();
686       }
687     }
688   else if (commandID == occupy_id)
689     {
690       PRINT("copy window\n");
691       w_window = GetWorkWindow(windowID);
692       if (w_window != NULL)
693 	CreateOccupy(w_window);
694     }
695   else if (commandID == copy_all_id)
696     {
697       PRINT("copy window\n");
698       w_window = GetWorkWindow(windowID);
699       if (w_window != NULL)
700 	CopyWindow(w_window,current_space,all_space);
701     }
702   else if (commandID == link_all_id)
703     {
704       PRINT("copy window\n");
705       w_window = GetWorkWindow(windowID);
706       if (w_window != NULL)
707 	LinkWindow(w_window,current_space,all_space);
708     }
709   else if (commandID == remove_id)
710     {
711       PRINT("remove id\n");
712       w_window = GetWorkWindow(windowID);
713       if (w_window != 0)
714 	{
715 	  if (w_window->s_list->next != NULL && w_window->window != None &&
716 	      _WSMGetConfigFormatType(w_window->window) != WSM_ICON_FMT)
717 	    DeleteWindow(w_window,current_space);
718       }
719     }
720   else if ((cs = GetCSFromSwitchID(commandID)) != NULL)
721     {
722       PRINT("SendLeaveRoom(%s)\n",cs->space->name);
723       XmToggleButtonSetState(wsm_ui->space_button[GetSpaceID(cs->space)],True,True);
724     }
725   else if ((cs = GetCSFromCopyID(commandID)) != NULL)
726     {
727       PRINT("copy space");
728       w_window = GetWorkWindow(windowID);
729       if (w_window != NULL)
730 	{
731 	  PRINT(" %s\n",cs->space->name);
732 	  CopyWindow(w_window,current_space, cs->space);
733 	}
734     }
735   else if ((cs = GetCSFromLinkID(commandID)) != NULL)
736     {
737       PRINT("link space");
738       w_window = GetWorkWindow(windowID);
739       if (w_window != NULL)
740 	{
741 	  PRINT(" %s\n",cs->space->name);
742 	  LinkWindow(w_window,current_space, cs->space);
743 	}
744     }
745 
746 
747 }
748 
749 
750 /*----------------------------------------------------------------------*
751   |                              GenerateSwitchMenu
752   |
753  *----------------------------------------------------------------------*/
754 void
GenerateSwitchMenu(void)755 GenerateSwitchMenu(void)
756 {
757   CommandSpace *cspace;
758 
759   switch_id = GET_COMMAND_ID(dsp);
760 
761   SendDefineCommand(0,switch_id, "_WSM_SWITCH_WORKSPACE", "Switch Workspace");
762 
763   for (cspace = command_space_list; cspace != NULL;
764        cspace = cspace->next)
765   {
766       SendDefineCommand(switch_id, cspace->switch_command_id,
767 			cspace->space->name, cspace->space->name);
768   }
769 }
770 
771 /*----------------------------------------------------------------------*
772   |                              SetInitialCommands
773   |
774  *----------------------------------------------------------------------*/
775 void
SetInitialCommands(void)776 SetInitialCommands(void)
777 {
778   Space *space;
779 /* all window stuff  */
780 
781   PRINT("set initial commands \n");
782   occupy_id = GET_COMMAND_ID(dsp);
783   copy_all_id = GET_COMMAND_ID(dsp);
784   link_all_id = GET_COMMAND_ID(dsp);
785   remove_id = GET_COMMAND_ID(dsp);
786   show_id = GET_COMMAND_ID(dsp);
787 
788   for (space = space_list; space != NULL; space = space->next)
789   {
790       (void)CreateCommandSpace(space, GET_COMMAND_ID(dsp),
791 			       GET_COMMAND_ID(dsp), GET_COMMAND_ID(dsp));
792   }
793 
794   SendDefineCommand(0,occupy_id, "_WSM_OCCUPY", "Occupy...");
795   SendDefineCommand(0,copy_all_id, "_WSM_COPY_ALL", "Copy To All");
796   SendDefineCommand(0,link_all_id, "_WSM_LINK_ALL", "Link To All");
797   SendDefineCommand(0,remove_id, "_WSM_REMOVE_FROM_WS",
798 		    "Remove From Workspace");
799   GenerateSwitchMenu();
800 
801   if (wsm_shown)
802       SendDefineCommand(0,show_id, "_WSM_HIDE_WSM", "Hide Workspace Manager");
803   else
804       SendDefineCommand(0,show_id, "_WSM_SHOW_WSM", "Show Workspace Manager");
805 
806   SendIncludeCommand(0x3fffffff,occupy_id,   True);
807   SendIncludeCommand(0x3fffffff,copy_all_id,   True);
808   SendIncludeCommand(0x3fffffff,link_all_id,   True);
809   SendIncludeCommand(0x3fffffff,remove_id, True);
810   SendIncludeCommand(0x00000000,switch_id, False);
811   SendIncludeCommand(0x00000000,show_id,   True);
812 
813 }
814 
815 
816 /*----------------------------------------------------------------------*
817  |                               AddWindow
818  | This will add commands to a new window
819  *----------------------------------------------------------------------*/
820 void
AddWindow(Window win)821 AddWindow(Window win)
822 {
823     SendIncludeCommand(win,occupy_id,   True);
824     SendIncludeCommand(win,copy_all_id,   True);
825     SendIncludeCommand(win,link_all_id,   True);
826     SendIncludeCommand(win,remove_id, True);
827 }
828 
829 /*----------------------------------------------------------------------*
830  |                               ShowWsmCommand
831  | This will add a Show or Hide Workspace Manager
832  *----------------------------------------------------------------------*/
833 void
ShowWsmCommand(void)834 ShowWsmCommand(void)
835 {
836     if (wsm_shown)
837 	SendRenameCommand(0x0, show_id, "Hide Workspace Manager");
838     else
839 	SendRenameCommand(0x0, show_id, "Show Workspace Manager");
840 }
841 
842 /*----------------------------------------------------------------------*
843  |                               AddSpaceCommand                        |
844  | This will add a new workspace name to the "Switch" root menu command.
845  *----------------------------------------------------------------------*/
846 void
AddSpaceCommand(Space * space)847 AddSpaceCommand(Space *space)
848 {
849   CommandSpace *cs =
850       CreateCommandSpace(space, GET_COMMAND_ID(dsp), GET_COMMAND_ID(dsp),
851 			 GET_COMMAND_ID(dsp));
852 
853   SendRemoveCommand(0x00000000,switch_id);
854   SendRemoveCommand(0x00000000,show_id);
855 
856   GenerateSwitchMenu();
857 
858   SendIncludeCommand(0x00000000,switch_id, False);
859   SendIncludeCommand(0x00000000,show_id, True);
860 }
861 
862 
863 
864 
865 /*----------------------------------------------------------------------*
866  |                               RemoveSpaceCommand                      |
867  *----------------------------------------------------------------------*/
868 void
RemoveSpaceCommand(int i)869 RemoveSpaceCommand(int i)
870 {
871   CommandSpace *cs = GetCSFromSpaceID(i);
872 
873   if (cs != NULL)
874     {
875       RemoveCommandSpace(cs);
876     }
877 
878   SendRemoveCommand(0x00000000,switch_id);
879   SendRemoveCommand(0x00000000,show_id);
880 
881   GenerateSwitchMenu();
882 
883   SendIncludeCommand(0x00000000,switch_id, False);
884   SendIncludeCommand(0x00000000,show_id, True);
885 }
886 
887 
888 
889 
890 /*----------------------------------------------------------------------*
891  |                           ChangeSpaceCommandName                     |
892  *----------------------------------------------------------------------*/
893 void
ChangeSpaceCommandName(Space * space)894 ChangeSpaceCommandName(Space *space)
895 {
896   CommandSpace *cs = GetCSFromSpace(space);
897   if (cs != NULL)
898     {
899 	SendRenameCommand(0x0, cs->switch_command_id, space->name);
900     }
901 }
902 
903 
904 
905 /*----------------------------------------------------------------------*
906  |                               DisableDeleteCommand                  |
907  *----------------------------------------------------------------------*/
908 void
DisableDeleteCommand(Window window)909 DisableDeleteCommand(Window window)
910 {
911   if (remove_id != 0)
912     {
913       SendDisableCommand(window,remove_id);
914     }
915 }
916 
917 
918 
919 
920 /*----------------------------------------------------------------------*
921  |                             EnableDeleteCommand                      |
922  *----------------------------------------------------------------------*/
923 void
EnableDeleteCommand(Window window)924 EnableDeleteCommand(Window window)
925 {
926   if (remove_id != 0)
927     {
928       SendEnableCommand(window,remove_id);
929     }
930 }
931 
932 
933 
934 /*----------------------------------------------------------------------*
935  |                          RemoveAllCommandsAndExit                    |
936  *----------------------------------------------------------------------*/
937 void
RemoveAllCommandsAndExit()938 RemoveAllCommandsAndExit()
939 {
940   Window rootWindow = XRootWindowOfScreen(XtScreen(shell));
941   PRINT("REMOVE ALL COMMANDS\n");
942   SendRemoveCommand(0x3fffffff,occupy_id);
943   SendRemoveCommand(0x3fffffff,copy_all_id);
944   SendRemoveCommand(0x3fffffff,link_all_id);
945   SendRemoveCommand(0x3fffffff,remove_id);
946   SendRemoveCommand(0x00000000,switch_id);
947   exiting = True;
948   SendRemoveCommand(0x00000000,show_id);
949 }
950 
951 
952 
953 /*----------------------------------------------------------------------*
954  |                              InternStuff                             |
955  *----------------------------------------------------------------------*/
956 void
InternStuff(Display * dsp)957 InternStuff (Display *dsp)
958 {
959   WM_S0                      = XInternAtom(dsp, "WM_S0", False);
960   _MOTIF_WM_DEFINE_COMMAND  = XInternAtom(dsp, "_MOTIF_WM_DEFINE_COMMAND", False);
961   _MOTIF_WM_INCLUDE_COMMAND = XInternAtom(dsp, "_MOTIF_WM_INCLUDE_COMMAND", False);
962   _MOTIF_WM_DISABLE_COMMAND = XInternAtom(dsp, "_MOTIF_WM_DISABLE_COMMAND", False);
963   _MOTIF_WM_ENABLE_COMMAND  = XInternAtom(dsp, "_MOTIF_WM_ENABLE_COMMAND", False);
964   _MOTIF_WM_INVOKE_COMMAND  = XInternAtom(dsp, "_MOTIF_WM_INVOKE_COMMAND", False);
965   _MOTIF_WM_REMOVE_COMMAND  = XInternAtom(dsp, "_MOTIF_WM_REMOVE_COMMAND", False);
966   _MOTIF_WM_RENAME_COMMAND  = XInternAtom(dsp, "_MOTIF_WM_RENAME_COMMAND", False);}
967 
968