1 /* dialog.c - dialog windows for internal use
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
28 #include <X11/keysym.h>
34 #include <sys/types.h>
45 #include <sys/signal.h>
49 #define PATH_MAX DEFAULT_PATH_MAX
52 #include "WindowMaker.h"
64 extern WPreferences wPreferences
;
66 static WMPoint
getCenter(WScreen
* scr
, int width
, int height
)
68 return wGetPointToCenterRectInHead(scr
, wGetHeadForPointerLocation(scr
), width
, height
);
71 int wMessageDialog(WScreen
* scr
, char *title
, char *message
, char *defBtn
, char *altBtn
, char *othBtn
)
79 panel
= WMCreateAlertPanel(scr
->wmscreen
, NULL
, title
, message
, defBtn
, altBtn
, othBtn
);
81 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 400, 180, 0, 0, 0);
83 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
85 center
= getCenter(scr
, 400, 180);
86 wwin
= wManageInternalWindow(scr
, parent
, None
, NULL
, center
.x
, center
.y
, 400, 180);
87 wwin
->client_leader
= WMWidgetXID(panel
->win
);
89 WMMapWidget(panel
->win
);
93 WMRunModalLoop(WMWidgetScreen(panel
->win
), WMWidgetView(panel
->win
));
95 result
= panel
->result
;
97 WMUnmapWidget(panel
->win
);
99 wUnmanageWindow(wwin
, False
, False
);
101 WMDestroyAlertPanel(panel
);
103 XDestroyWindow(dpy
, parent
);
108 void toggleSaveSession(WMWidget
* w
, void *data
)
110 wPreferences
.save_session_on_exit
= WMGetButtonSelected((WMButton
*) w
);
113 int wExitDialog(WScreen
* scr
, char *title
, char *message
, char *defBtn
, char *altBtn
, char *othBtn
)
116 WMButton
*saveSessionBtn
;
122 panel
= WMCreateAlertPanel(scr
->wmscreen
, NULL
, title
, message
, defBtn
, altBtn
, othBtn
);
124 /* add save session button */
125 saveSessionBtn
= WMCreateSwitchButton(panel
->hbox
);
126 WMSetButtonAction(saveSessionBtn
, toggleSaveSession
, NULL
);
127 WMAddBoxSubview(panel
->hbox
, WMWidgetView(saveSessionBtn
), False
, True
, 200, 0, 0);
128 WMSetButtonText(saveSessionBtn
, _("Save workspace state"));
129 WMSetButtonSelected(saveSessionBtn
, wPreferences
.save_session_on_exit
);
130 WMRealizeWidget(saveSessionBtn
);
131 WMMapWidget(saveSessionBtn
);
133 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 400, 180, 0, 0, 0);
135 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
137 center
= getCenter(scr
, 400, 180);
138 wwin
= wManageInternalWindow(scr
, parent
, None
, NULL
, center
.x
, center
.y
, 400, 180);
140 wwin
->client_leader
= WMWidgetXID(panel
->win
);
142 WMMapWidget(panel
->win
);
146 WMRunModalLoop(WMWidgetScreen(panel
->win
), WMWidgetView(panel
->win
));
148 result
= panel
->result
;
150 WMUnmapWidget(panel
->win
);
152 wUnmanageWindow(wwin
, False
, False
);
154 WMDestroyAlertPanel(panel
);
156 XDestroyWindow(dpy
, parent
);
161 typedef struct _WMInputPanelWithHistory
{
170 } WMInputPanelWithHistory
;
172 static char *HistoryFileName(char *name
)
174 char *filename
= NULL
;
176 filename
= wstrdup(wusergnusteppath());
177 filename
= wstrappend(filename
, "/.AppInfo/WindowMaker/History");
178 if (name
&& strlen(name
)) {
179 filename
= wstrappend(filename
, ".");
180 filename
= wstrappend(filename
, name
);
185 static int matchString(void *str1
, void *str2
)
187 return (strcmp((char *)str1
, (char *)str2
) == 0 ? 1 : 0);
190 static WMArray
*LoadHistory(char *filename
, int max
)
192 WMPropList
*plhistory
;
197 history
= WMCreateArrayWithDestructor(1, wfree
);
198 WMAddToArray(history
, wstrdup(""));
200 plhistory
= WMReadPropListFromFile((char *)filename
);
202 if (plhistory
&& WMIsPLArray(plhistory
)) {
203 num
= WMGetPropListItemCount(plhistory
);
207 for (i
= 0; i
< num
; ++i
) {
208 plitem
= WMGetFromPLArray(plhistory
, i
);
209 if (WMIsPLString(plitem
) && WMFindInArray(history
, matchString
,
210 WMGetFromPLString(plitem
)) == WANotFound
)
211 WMAddToArray(history
, WMGetFromPLString(plitem
));
218 static void SaveHistory(WMArray
* history
, char *filename
)
221 WMPropList
*plhistory
;
223 plhistory
= WMCreatePLArray(NULL
);
225 for (i
= 0; i
< WMGetArrayItemCount(history
); ++i
)
226 WMAddToPLArray(plhistory
, WMCreatePLString(WMGetFromArray(history
, i
)));
228 WMWritePropListToFile(plhistory
, (char *)filename
, True
);
229 WMReleasePropList(plhistory
);
232 static int strmatch(const char *str1
, const char *str2
)
234 return !strcmp(str1
, str2
);
237 static int pstrcmp(const char **str1
, const char **str2
)
239 return strcmp(*str1
, *str2
);
243 ScanFiles(const char *dir
, const char *prefix
, unsigned acceptmask
, unsigned declinemask
, WMArray
* result
)
249 char *fullfilename
, *suffix
;
251 prefixlen
= strlen(prefix
);
252 if ((d
= opendir(dir
)) != NULL
) {
253 while ((de
= readdir(d
)) != NULL
) {
254 if (strlen(de
->d_name
) > prefixlen
&&
255 !strncmp(prefix
, de
->d_name
, prefixlen
) &&
256 strcmp(de
->d_name
, ".") != 0 && strcmp(de
->d_name
, "..")) {
257 fullfilename
= wstrconcat((char *)dir
, "/");
258 fullfilename
= wstrappend(fullfilename
, de
->d_name
);
260 if (stat(fullfilename
, &sb
) == 0 &&
261 (sb
.st_mode
& acceptmask
) &&
262 !(sb
.st_mode
& declinemask
) &&
263 WMFindInArray(result
, (WMMatchDataProc
*) strmatch
,
264 de
->d_name
+ prefixlen
) == WANotFound
) {
265 suffix
= wstrdup(de
->d_name
+ prefixlen
);
266 WMAddToArray(result
, suffix
);
275 static WMArray
*GenerateVariants(const char *complete
)
277 Bool firstWord
= True
;
278 WMArray
*variants
= NULL
;
279 char *pos
= NULL
, *path
= NULL
, *tmp
= NULL
, *dir
= NULL
, *prefix
= NULL
;
281 variants
= WMCreateArrayWithDestructor(0, wfree
);
283 while (*complete
== ' ')
286 if ((pos
= strrchr(complete
, ' ')) != NULL
) {
291 if ((pos
= strrchr(complete
, '/')) != NULL
) {
292 tmp
= wstrndup((char *)complete
, pos
- complete
+ 1);
293 if (*tmp
== '~' && *(tmp
+ 1) == '/' && getenv("HOME")) {
294 dir
= wstrdup(getenv("HOME"));
295 dir
= wstrappend(dir
, tmp
+ 1);
300 prefix
= wstrdup(pos
+ 1);
301 ScanFiles(dir
, prefix
, (unsigned)-1, 0, variants
);
304 } else if (*complete
== '~') {
305 WMAddToArray(variants
, wstrdup("/"));
306 } else if (firstWord
) {
307 path
= getenv("PATH");
309 pos
= strchr(path
, ':');
311 tmp
= wstrndup(path
, pos
- path
);
313 } else if (*path
!= '\0') {
318 ScanFiles(tmp
, complete
, S_IXOTH
| S_IXGRP
| S_IXUSR
, S_IFDIR
, variants
);
323 WMSortArray(variants
, (WMCompareDataProc
*) pstrcmp
);
327 static void handleHistoryKeyPress(XEvent
* event
, void *clientData
)
331 WMInputPanelWithHistory
*p
= (WMInputPanelWithHistory
*) clientData
;
334 ksym
= XLookupKeysym(&event
->xkey
, 0);
338 if (p
->histpos
< WMGetArrayItemCount(p
->history
) - 1) {
340 wfree(WMReplaceInArray(p
->history
, 0, WMGetTextFieldText(p
->panel
->text
)));
342 WMSetTextFieldText(p
->panel
->text
, WMGetFromArray(p
->history
, p
->histpos
));
346 if (p
->histpos
> 0) {
348 WMSetTextFieldText(p
->panel
->text
, WMGetFromArray(p
->history
, p
->histpos
));
353 text
= WMGetTextFieldText(p
->panel
->text
);
354 pos
= WMGetTextFieldCursorPosition(p
->panel
->text
);
355 p
->prefix
= wstrndup(text
, pos
);
356 p
->suffix
= wstrdup(text
+ pos
);
358 p
->variants
= GenerateVariants(p
->prefix
);
367 if (p
->variants
&& p
->prefix
&& p
->suffix
) {
369 if (p
->varpos
> WMGetArrayItemCount(p
->variants
))
372 text
= wstrconcat(p
->prefix
, WMGetFromArray(p
->variants
, p
->varpos
- 1));
374 text
= wstrdup(p
->prefix
);
376 text
= wstrappend(text
, p
->suffix
);
377 WMSetTextFieldText(p
->panel
->text
, text
);
378 WMSetTextFieldCursorPosition(p
->panel
->text
, pos
);
383 if (ksym
!= XK_Tab
) {
393 WMFreeArray(p
->variants
);
399 int wAdvancedInputDialog(WScreen
* scr
, char *title
, char *message
, char *name
, char **text
)
405 WMInputPanelWithHistory
*p
;
408 filename
= HistoryFileName(name
);
409 p
= wmalloc(sizeof(WMInputPanelWithHistory
));
410 p
->panel
= WMCreateInputPanel(scr
->wmscreen
, NULL
, title
, message
, *text
, _("OK"), _("Cancel"));
411 p
->history
= LoadHistory(filename
, wPreferences
.history_lines
);
418 WMCreateEventHandler(WMWidgetView(p
->panel
->text
), KeyPressMask
, handleHistoryKeyPress
, p
);
420 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 320, 160, 0, 0, 0);
421 XSelectInput(dpy
, parent
, KeyPressMask
| KeyReleaseMask
);
423 XReparentWindow(dpy
, WMWidgetXID(p
->panel
->win
), parent
, 0, 0);
425 center
= getCenter(scr
, 320, 160);
426 wwin
= wManageInternalWindow(scr
, parent
, None
, NULL
, center
.x
, center
.y
, 320, 160);
428 wwin
->client_leader
= WMWidgetXID(p
->panel
->win
);
430 WMMapWidget(p
->panel
->win
);
434 WMRunModalLoop(WMWidgetScreen(p
->panel
->win
), WMWidgetView(p
->panel
->win
));
436 if (p
->panel
->result
== WAPRDefault
) {
437 result
= WMGetTextFieldText(p
->panel
->text
);
438 wfree(WMReplaceInArray(p
->history
, 0, wstrdup(result
)));
439 SaveHistory(p
->history
, filename
);
443 wUnmanageWindow(wwin
, False
, False
);
445 WMDestroyInputPanel(p
->panel
);
446 WMFreeArray(p
->history
);
450 XDestroyWindow(dpy
, parent
);
463 int wInputDialog(WScreen
* scr
, char *title
, char *message
, char **text
)
471 panel
= WMCreateInputPanel(scr
->wmscreen
, NULL
, title
, message
, *text
, _("OK"), _("Cancel"));
473 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 320, 160, 0, 0, 0);
474 XSelectInput(dpy
, parent
, KeyPressMask
| KeyReleaseMask
);
476 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
478 center
= getCenter(scr
, 320, 160);
479 wwin
= wManageInternalWindow(scr
, parent
, None
, NULL
, center
.x
, center
.y
, 320, 160);
481 wwin
->client_leader
= WMWidgetXID(panel
->win
);
483 WMMapWidget(panel
->win
);
487 WMRunModalLoop(WMWidgetScreen(panel
->win
), WMWidgetView(panel
->win
));
489 if (panel
->result
== WAPRDefault
)
490 result
= WMGetTextFieldText(panel
->text
);
494 wUnmanageWindow(wwin
, False
, False
);
496 WMDestroyInputPanel(panel
);
498 XDestroyWindow(dpy
, parent
);
512 *****************************************************************
513 * Icon Selection Panel
514 *****************************************************************
517 typedef struct IconPanel
{
530 WMButton
*previewButton
;
535 WMTextField
*fileField
;
538 WMButton
*cancelButton
;
540 WMButton
*chooseButton
;
547 static void listPixmaps(WScreen
* scr
, WMList
* lPtr
, char *path
)
549 struct dirent
*dentry
;
551 char pbuf
[PATH_MAX
+ 16];
553 IconPanel
*panel
= WMGetHangedData(lPtr
);
555 panel
->preview
= False
;
557 apath
= wexpandpath(path
);
558 dir
= opendir(apath
);
563 tmp
= _("Could not open directory ");
564 msg
= wmalloc(strlen(tmp
) + strlen(path
) + 6);
568 wMessageDialog(scr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
574 /* list contents in the column */
575 while ((dentry
= readdir(dir
))) {
578 if (strcmp(dentry
->d_name
, ".") == 0 || strcmp(dentry
->d_name
, "..") == 0)
583 strcat(pbuf
, dentry
->d_name
);
585 if (stat(pbuf
, &statb
) < 0)
588 if (statb
.st_mode
& (S_IRUSR
| S_IRGRP
| S_IROTH
)
589 && statb
.st_mode
& (S_IFREG
| S_IFLNK
)) {
590 WMAddListItem(lPtr
, dentry
->d_name
);
593 WMSortListItems(lPtr
);
597 panel
->preview
= True
;
600 static void setViewedImage(IconPanel
* panel
, char *file
)
609 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
), file
, &color
);
611 WMSetButtonEnabled(panel
->okButton
, False
);
613 WMSetLabelText(panel
->iconView
, _("Could not load image file "));
615 WMSetLabelImage(panel
->iconView
, NULL
);
617 WMSetButtonEnabled(panel
->okButton
, True
);
619 WMSetLabelText(panel
->iconView
, NULL
);
620 WMSetLabelImage(panel
->iconView
, pixmap
);
621 WMReleasePixmap(pixmap
);
625 static void listCallback(void *self
, void *data
)
627 WMList
*lPtr
= (WMList
*) self
;
628 IconPanel
*panel
= (IconPanel
*) data
;
631 if (lPtr
== panel
->dirList
) {
632 WMListItem
*item
= WMGetListSelectedItem(lPtr
);
638 WMSetTextFieldText(panel
->fileField
, path
);
640 WMSetLabelImage(panel
->iconView
, NULL
);
642 WMSetButtonEnabled(panel
->okButton
, False
);
644 WMClearList(panel
->iconList
);
645 listPixmaps(panel
->scr
, panel
->iconList
, path
);
647 char *tmp
, *iconFile
;
648 WMListItem
*item
= WMGetListSelectedItem(panel
->dirList
);
653 tmp
= wexpandpath(path
);
655 item
= WMGetListSelectedItem(panel
->iconList
);
658 iconFile
= item
->text
;
660 path
= wmalloc(strlen(tmp
) + strlen(iconFile
) + 4);
663 strcat(path
, iconFile
);
665 WMSetTextFieldText(panel
->fileField
, path
);
666 setViewedImage(panel
, path
);
671 static void listIconPaths(WMList
* lPtr
)
676 paths
= wstrdup(wPreferences
.icon_path
);
678 path
= strtok(paths
, ":");
683 tmp
= wexpandpath(path
);
684 /* do not sort, because the order implies the order of
685 * directories searched */
686 if (access(tmp
, X_OK
) == 0)
687 WMAddListItem(lPtr
, path
);
689 } while ((path
= strtok(NULL
, ":")) != NULL
);
694 static void drawIconProc(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
696 IconPanel
*panel
= WMGetHangedData(lPtr
);
697 WScreen
*scr
= panel
->scr
;
698 GC gc
= scr
->draw_gc
;
699 GC copygc
= scr
->copy_gc
;
700 char *file
, *dirfile
;
704 WMScreen
*wmscr
= WMWidgetScreen(panel
->win
);
706 int x
, y
, width
, height
, len
;
713 width
= rect
->size
.width
;
714 height
= rect
->size
.height
;
716 back
= (state
& WLDSSelected
) ? scr
->white
: scr
->gray
;
718 dirfile
= wexpandpath(WMGetListSelectedItem(panel
->dirList
)->text
);
719 len
= strlen(dirfile
) + strlen(text
) + 4;
721 snprintf(file
, len
, "%s/%s", dirfile
, text
);
724 color
.red
= WMRedComponentOfColor(back
) >> 8;
725 color
.green
= WMGreenComponentOfColor(back
) >> 8;
726 color
.blue
= WMBlueComponentOfColor(back
) >> 8;
727 color
.alpha
= WMGetColorAlpha(back
) >> 8;
729 pixmap
= WMCreateBlendedPixmapFromFile(wmscr
, file
, &color
);
733 /*WMRemoveListItem(lPtr, index); */
737 XFillRectangle(dpy
, d
, WMColorGC(back
), x
, y
, width
, height
);
739 XSetClipMask(dpy
, gc
, None
);
740 /*XDrawRectangle(dpy, d, WMColorGC(white), x+5, y+5, width-10, 54); */
741 XDrawLine(dpy
, d
, WMColorGC(scr
->white
), x
, y
+ height
- 1, x
+ width
, y
+ height
- 1);
743 size
= WMGetPixmapSize(pixmap
);
745 XSetClipMask(dpy
, copygc
, WMGetPixmapMaskXID(pixmap
));
746 XSetClipOrigin(dpy
, copygc
, x
+ (width
- size
.width
) / 2, y
+ 2);
747 XCopyArea(dpy
, WMGetPixmapXID(pixmap
), d
, copygc
, 0, 0,
748 size
.width
> 100 ? 100 : size
.width
, size
.height
> 64 ? 64 : size
.height
,
749 x
+ (width
- size
.width
) / 2, y
+ 2);
753 int fheight
= WMFontHeight(panel
->normalfont
);
754 int tlen
= strlen(text
);
755 int twidth
= WMWidthOfString(panel
->normalfont
, text
, tlen
);
758 ofx
= x
+ (width
- twidth
) / 2;
759 ofy
= y
+ 64 - fheight
;
761 for (i
= -1; i
< 2; i
++)
762 for (j
= -1; j
< 2; j
++)
763 WMDrawString(wmscr
, d
, scr
->white
, panel
->normalfont
,
764 ofx
+ i
, ofy
+ j
, text
, tlen
);
766 WMDrawString(wmscr
, d
, scr
->black
, panel
->normalfont
, ofx
, ofy
, text
, tlen
);
769 WMReleasePixmap(pixmap
);
770 /* I hope it is better to do not use cache / on my box it is fast nuff */
774 static void buttonCallback(void *self
, void *clientData
)
776 WMButton
*bPtr
= (WMButton
*) self
;
777 IconPanel
*panel
= (IconPanel
*) clientData
;
779 if (bPtr
== panel
->okButton
) {
781 panel
->result
= True
;
782 } else if (bPtr
== panel
->cancelButton
) {
784 panel
->result
= False
;
785 } else if (bPtr
== panel
->previewButton
) {
786 /**** Previewer ****/
787 WMSetButtonEnabled(bPtr
, False
);
788 WMSetListUserDrawItemHeight(panel
->iconList
, 68);
789 WMSetListUserDrawProc(panel
->iconList
, drawIconProc
);
790 WMRedisplayWidget(panel
->iconList
);
791 /* for draw proc to access screen/gc */
792 /*** end preview ***/
795 else if (bPtr
== panel
->chooseButton
) {
798 op
= WMCreateOpenPanel(WMWidgetScreen(bPtr
));
800 if (WMRunModalFilePanelForDirectory(op
, NULL
, "/usr/local", NULL
, NULL
)) {
802 path
= WMGetFilePanelFile(op
);
803 WMSetTextFieldText(panel
->fileField
, path
);
804 setViewedImage(panel
, path
);
807 WMDestroyFilePanel(op
);
812 static void keyPressHandler(XEvent
* event
, void *data
)
814 IconPanel
*panel
= (IconPanel
*) data
;
823 if (event
->type
== KeyRelease
)
827 count
= XLookupString(&event
->xkey
, buffer
, sizeof(buffer
), &ksym
, NULL
);
829 iidx
= WMGetListSelectedItemRow(panel
->iconList
);
830 didx
= WMGetListSelectedItemRow(panel
->dirList
);
838 list
= panel
->iconList
;
841 if (iidx
< WMGetListNumberOfRows(panel
->iconList
) - 1)
845 list
= panel
->iconList
;
849 list
= panel
->iconList
;
852 item
= WMGetListNumberOfRows(panel
->iconList
) - 1;
853 list
= panel
->iconList
;
856 if (didx
< WMGetListNumberOfRows(panel
->dirList
) - 1)
860 list
= panel
->dirList
;
867 list
= panel
->dirList
;
870 WMPerformButtonClick(panel
->okButton
);
873 WMPerformButtonClick(panel
->cancelButton
);
878 WMSelectListItem(list
, item
);
879 WMSetListPosition(list
, item
- 5);
880 listCallback(list
, panel
);
884 Bool
wIconChooserDialog(WScreen
* scr
, char **file
, char *instance
, char *class)
893 panel
= wmalloc(sizeof(IconPanel
));
894 memset(panel
, 0, sizeof(IconPanel
));
898 panel
->win
= WMCreateWindow(scr
->wmscreen
, "iconChooser");
899 WMResizeWidget(panel
->win
, 450, 280);
901 WMCreateEventHandler(WMWidgetView(panel
->win
), KeyPressMask
| KeyReleaseMask
, keyPressHandler
, panel
);
903 boldFont
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
904 panel
->normalfont
= WMSystemFontOfSize(WMWidgetScreen(panel
->win
), 12);
906 panel
->dirLabel
= WMCreateLabel(panel
->win
);
907 WMResizeWidget(panel
->dirLabel
, 200, 20);
908 WMMoveWidget(panel
->dirLabel
, 10, 7);
909 WMSetLabelText(panel
->dirLabel
, _("Directories"));
910 WMSetLabelFont(panel
->dirLabel
, boldFont
);
911 WMSetLabelTextAlignment(panel
->dirLabel
, WACenter
);
913 WMSetLabelRelief(panel
->dirLabel
, WRSunken
);
915 panel
->iconLabel
= WMCreateLabel(panel
->win
);
916 WMResizeWidget(panel
->iconLabel
, 140, 20);
917 WMMoveWidget(panel
->iconLabel
, 215, 7);
918 WMSetLabelText(panel
->iconLabel
, _("Icons"));
919 WMSetLabelFont(panel
->iconLabel
, boldFont
);
920 WMSetLabelTextAlignment(panel
->iconLabel
, WACenter
);
922 WMReleaseFont(boldFont
);
924 color
= WMWhiteColor(scr
->wmscreen
);
925 WMSetLabelTextColor(panel
->dirLabel
, color
);
926 WMSetLabelTextColor(panel
->iconLabel
, color
);
927 WMReleaseColor(color
);
929 color
= WMDarkGrayColor(scr
->wmscreen
);
930 WMSetWidgetBackgroundColor(panel
->iconLabel
, color
);
931 WMSetWidgetBackgroundColor(panel
->dirLabel
, color
);
932 WMReleaseColor(color
);
934 WMSetLabelRelief(panel
->iconLabel
, WRSunken
);
936 panel
->dirList
= WMCreateList(panel
->win
);
937 WMResizeWidget(panel
->dirList
, 200, 170);
938 WMMoveWidget(panel
->dirList
, 10, 30);
939 WMSetListAction(panel
->dirList
, listCallback
, panel
);
941 panel
->iconList
= WMCreateList(panel
->win
);
942 WMResizeWidget(panel
->iconList
, 140, 170);
943 WMMoveWidget(panel
->iconList
, 215, 30);
944 WMSetListAction(panel
->iconList
, listCallback
, panel
);
946 WMHangData(panel
->iconList
, panel
);
948 panel
->previewButton
= WMCreateCommandButton(panel
->win
);
949 WMResizeWidget(panel
->previewButton
, 75, 26);
950 WMMoveWidget(panel
->previewButton
, 365, 130);
951 WMSetButtonText(panel
->previewButton
, _("Preview"));
952 WMSetButtonAction(panel
->previewButton
, buttonCallback
, panel
);
954 panel
->iconView
= WMCreateLabel(panel
->win
);
955 WMResizeWidget(panel
->iconView
, 75, 75);
956 WMMoveWidget(panel
->iconView
, 365, 40);
957 WMSetLabelImagePosition(panel
->iconView
, WIPOverlaps
);
958 WMSetLabelRelief(panel
->iconView
, WRSunken
);
959 WMSetLabelTextAlignment(panel
->iconView
, WACenter
);
961 panel
->fileLabel
= WMCreateLabel(panel
->win
);
962 WMResizeWidget(panel
->fileLabel
, 80, 20);
963 WMMoveWidget(panel
->fileLabel
, 10, 210);
964 WMSetLabelText(panel
->fileLabel
, _("File Name:"));
966 panel
->fileField
= WMCreateTextField(panel
->win
);
967 WMSetViewNextResponder(WMWidgetView(panel
->fileField
), WMWidgetView(panel
->win
));
968 WMResizeWidget(panel
->fileField
, 345, 20);
969 WMMoveWidget(panel
->fileField
, 95, 210);
970 WMSetTextFieldEditable(panel
->fileField
, False
);
972 panel
->okButton
= WMCreateCommandButton(panel
->win
);
973 WMResizeWidget(panel
->okButton
, 80, 26);
974 WMMoveWidget(panel
->okButton
, 360, 240);
975 WMSetButtonText(panel
->okButton
, _("OK"));
976 WMSetButtonEnabled(panel
->okButton
, False
);
977 WMSetButtonAction(panel
->okButton
, buttonCallback
, panel
);
979 panel
->cancelButton
= WMCreateCommandButton(panel
->win
);
980 WMResizeWidget(panel
->cancelButton
, 80, 26);
981 WMMoveWidget(panel
->cancelButton
, 270, 240);
982 WMSetButtonText(panel
->cancelButton
, _("Cancel"));
983 WMSetButtonAction(panel
->cancelButton
, buttonCallback
, panel
);
985 panel
->chooseButton
= WMCreateCommandButton(panel
->win
);
986 WMResizeWidget(panel
->chooseButton
, 110, 26);
987 WMMoveWidget(panel
->chooseButton
, 150, 240);
988 WMSetButtonText(panel
->chooseButton
, _("Choose File"));
989 WMSetButtonAction(panel
->chooseButton
, buttonCallback
, panel
);
991 WMRealizeWidget(panel
->win
);
992 WMMapSubwidgets(panel
->win
);
994 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 450, 280, 0, 0, 0);
996 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
1000 int len
= (instance
? strlen(instance
) : 0)
1001 + (class ? strlen(class) : 0) + 32;
1006 if (tmp
&& (instance
|| class))
1007 snprintf(tmp
, len
, "%s [%s.%s]", _("Icon Chooser"), instance
, class);
1009 strcpy(tmp
, _("Icon Chooser"));
1011 center
= getCenter(scr
, 450, 280);
1013 wwin
= wManageInternalWindow(scr
, parent
, None
, tmp
, center
.x
, center
.y
, 450, 280);
1017 /* put icon paths in the list */
1018 listIconPaths(panel
->dirList
);
1020 WMMapWidget(panel
->win
);
1024 while (!panel
->done
) {
1027 WMNextEvent(dpy
, &event
);
1028 WMHandleEvent(&event
);
1031 if (panel
->result
) {
1032 char *defaultPath
, *wantedPath
;
1034 /* check if the file the user selected is not the one that
1035 * would be loaded by default with the current search path */
1036 *file
= WMGetListSelectedItem(panel
->iconList
)->text
;
1041 defaultPath
= FindImage(wPreferences
.icon_path
, *file
);
1042 wantedPath
= WMGetTextFieldText(panel
->fileField
);
1043 /* if the file is not the default, use full path */
1044 if (strcmp(wantedPath
, defaultPath
) != 0) {
1047 *file
= wstrdup(*file
);
1056 result
= panel
->result
;
1058 WMReleaseFont(panel
->normalfont
);
1060 WMUnmapWidget(panel
->win
);
1062 WMDestroyWidget(panel
->win
);
1064 wUnmanageWindow(wwin
, False
, False
);
1068 XDestroyWindow(dpy
, parent
);
1074 ***********************************************************************
1076 ***********************************************************************
1109 #define COPYRIGHT_TEXT \
1110 "Copyright \xc2\xa9 1997-2006 Alfredo K. Kojima\n"\
1111 "Copyright \xc2\xa9 1998-2006 Dan Pascu"
1113 static InfoPanel
*thePanel
= NULL
;
1115 static void destroyInfoPanel(WCoreWindow
* foo
, void *data
, XEvent
* event
)
1118 if (thePanel
->timer
) {
1119 WMDeleteTimerHandler(thePanel
->timer
);
1121 if (thePanel
->oldPix
) {
1122 WMReleasePixmap(thePanel
->oldPix
);
1124 if (thePanel
->oldFont
) {
1125 WMReleaseFont(thePanel
->oldFont
);
1127 if (thePanel
->icon
) {
1128 RReleaseImage(thePanel
->icon
);
1130 if (thePanel
->pic
) {
1131 RReleaseImage(thePanel
->pic
);
1133 #endif /* SILLYNESS */
1134 WMUnmapWidget(thePanel
);
1136 wUnmanageWindow(thePanel
->wwin
, False
, False
);
1138 WMDestroyWidget(thePanel
->win
);
1147 extern WMPixmap
*DoXThing();
1148 extern Bool
InitXThing();
1150 static void logoPushCallback(void *data
)
1152 InfoPanel
*panel
= (InfoPanel
*) data
;
1155 static int oldi
= 0;
1157 static int jingobeu
[] = {
1158 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
1159 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
1160 329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
1165 XKeyboardControl kc
;
1166 XKeyboardState ksave
;
1167 unsigned long mask
= KBBellPitch
| KBBellDuration
| KBBellPercent
;
1169 XGetKeyboardControl(dpy
, &ksave
);
1172 if (jingobeu
[panel
->x
- 1] == 0) {
1174 } else if (jingobeu
[panel
->x
- 1] < 0) {
1176 c
= jingobeu
[panel
->x
- 1] / 50;
1178 } else if (c
== 0) {
1179 kc
.bell_percent
= 50;
1180 kc
.bell_pitch
= jingobeu
[panel
->x
- 1];
1182 kc
.bell_duration
= jingobeu
[panel
->x
- 1];
1183 c
= jingobeu
[panel
->x
- 1] / 50;
1185 XChangeKeyboardControl(dpy
, mask
, &kc
);
1192 if (!(panel
->cycle
% 4)) {
1195 p
= DoXThing(panel
->wwin
);
1196 WMSetLabelImage(panel
->logoL
, p
);
1198 kc
.bell_pitch
= ksave
.bell_pitch
;
1199 kc
.bell_percent
= ksave
.bell_percent
;
1200 kc
.bell_duration
= ksave
.bell_duration
;
1201 XChangeKeyboardControl(dpy
, mask
, &kc
);
1202 } else if (panel
->cycle
< 30) {
1212 image
= RScaleImage(panel
->icon
, panel
->pic
->width
, panel
->pic
->height
);
1213 RCombineImagesWithOpaqueness(image
, panel
->pic
, panel
->cycle
* 255 / 30);
1214 pix
= WMCreateBlendedPixmapFromRImage(panel
->scr
->wmscreen
, image
, &gray
);
1215 RReleaseImage(image
);
1216 WMSetLabelImage(panel
->logoL
, pix
);
1217 WMReleasePixmap(pix
);
1220 /* slow down text a little */
1221 i
= (int)(panel
->cycle
* 50.0 / 85.0) % 200;
1224 len
= strlen(panel
->str
);
1226 strncpy(buffer
, panel
->str
, i
< len
? i
: len
);
1228 memset(&buffer
[len
], ' ', i
- len
);
1230 strncpy(buffer
, panel
->str
, i
< len
? i
: len
);
1232 memset(&buffer
[len
], ' ', i
- len
);
1235 WMSetLabelText(panel
->versionL
, buffer
);
1237 XFlush(WMScreenDisplay(WMWidgetScreen(panel
->versionL
)));
1242 panel
->timer
= WMAddTimerHandler(50, logoPushCallback
, panel
);
1246 static void handleLogoPush(XEvent
* event
, void *data
)
1248 InfoPanel
*panel
= (InfoPanel
*) data
;
1249 static int broken
= 0;
1250 static int clicks
= 0;
1251 static char *pic_data
[] = {
1310 " ............... ",
1311 " ....XoO+@##+O$%.... ",
1312 " ...%X&*========-;;:o... ",
1313 " ...>.>,<122222222222134@... ",
1314 " ..>5678912222222222222220q%.. ",
1315 " ..$.&-w2222222222222222222er>.. ",
1316 " ..O.t31222222222222222222222y4>.. ",
1317 " ...O5u3222222222222222222222222yri... ",
1318 " ..>p&a22222222222222222222222222wso.. ",
1319 " ..ids91222222222222222222222222222wfi.. ",
1320 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
1321 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
1322 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
1323 " ..o7y22222222v...r222222223hX.i82222221si.. ",
1324 "..io*222222222&...u22222222yt..%*22222220:%. ",
1325 "..>k02222222227...f222222222v..X=222222229t. ",
1326 "..dz12222222220ui:y2222222223d%qw222222221g. ",
1327 ".%vw222222222221y2222222222219*y2222222222wd.",
1328 ".X;2222222222222222222222222222222222222222b.",
1329 ".i*2222222222222222222222222222222222222222v.",
1330 ".i*2222222222222222222222222222222222222222;.",
1331 ".i*22222222222222222222222222222222222222228.",
1332 ".>*2222222222222222222222222222222222222222=.",
1333 ".i*22222222222222222222222222222222222222228.",
1334 ".i*2222222222222222222222222222222222222222;.",
1335 ".X*222222222222222222222222222222we12222222r.",
1336 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
1337 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
1338 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
1339 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
1340 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
1341 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
1342 " ...:e2222218mdz22222222222222a&$vw222220@...",
1343 " ...O-122222y:.u02222222222229q$uj222221r... ",
1344 " ..%&a1222223&573w2222222219NOxz122221z>... ",
1345 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
1346 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
1347 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
1348 " ..Xb9122222109g-****;<y22221zn%... ",
1349 " ..X&801222222222222222222w-h.... ",
1350 " ...o:=022222222222222221=lX... ",
1351 " ..X@:;3w2222222222210fO... ",
1352 " ...XX&v8<30000003-N@... ",
1353 " .....XmnbN:q&Bo.... ",
1356 static char *msgs
[] = {
1358 "Focus follow mouse users will burn in hell!!!",
1360 "Hi! My name is bobby...",
1361 "AHH! The neurotic monkeys are after me!",
1363 "HOW ARE YOU GENTLEMEN?",
1365 "SOMEBODY SET UP US THE BOMB",
1366 "ALL YOUR BASE ARE BELONG TO US!",
1367 "Oh My God!!! Larry is back!",
1368 "Alex Perez is aliveeeeeeee!!!"
1373 if (!panel
->timer
&& !broken
&& clicks
> 0) {
1379 panel
->icon
= WMGetApplicationIconImage(panel
->scr
->wmscreen
);
1391 panel
->icon
= RCloneImage(panel
->icon
);
1392 RCombineImageWithColor(panel
->icon
, &color
);
1396 panel
->pic
= RGetImageFromXPMData(panel
->scr
->rcontext
, pic_data
);
1399 RReleaseImage(panel
->icon
);
1405 panel
->str
= msgs
[rand() % (sizeof(msgs
) / sizeof(char *))];
1407 panel
->timer
= WMAddTimerHandler(50, logoPushCallback
, panel
);
1409 panel
->oldPix
= WMRetainPixmap(WMGetLabelImage(panel
->logoL
));
1410 /* If we don't use a fixed font, scrolling will be jumpy */
1411 /* Alternatively we can draw text in a pixmap and scroll it smoothly */
1412 if ((panel
->oldFont
= WMGetLabelFont(panel
->versionL
)) != NULL
)
1413 WMRetainFont(panel
->oldFont
);
1414 font
= WMCreateFont(WMWidgetScreen(panel
->versionL
),
1415 "Lucida Console,Courier New,monospace:pixelsize=12");
1417 WMSetLabelFont(panel
->versionL
, font
);
1418 WMReleaseFont(font
);
1420 WMSetLabelText(panel
->versionL
, "");
1421 } else if (panel
->timer
) {
1426 WMSetLabelImage(panel
->logoL
, panel
->oldPix
);
1427 WMReleasePixmap(panel
->oldPix
);
1428 panel
->oldPix
= NULL
;
1430 WMDeleteTimerHandler(panel
->timer
);
1431 panel
->timer
= NULL
;
1433 WMSetLabelFont(panel
->versionL
, panel
->oldFont
);
1434 if (panel
->oldFont
) {
1435 WMReleaseFont(panel
->oldFont
);
1436 panel
->oldFont
= NULL
;
1438 snprintf(version
, sizeof(version
), _("Version %s"), VERSION
);
1439 WMSetLabelText(panel
->versionL
, version
);
1440 XFlush(WMScreenDisplay(WMWidgetScreen(panel
->versionL
)));
1445 while (XCheckTypedWindowEvent(dpy
, WMWidgetXID(panel
->versionL
), ButtonPress
, &ev
)) ;
1448 #endif /* SILLYNESS */
1450 void wShowInfoPanel(WScreen
* scr
)
1456 char *strbuf
= NULL
;
1462 int i
, width
= 50, sepHeight
;
1473 if (thePanel
->scr
== scr
) {
1474 wRaiseFrame(thePanel
->wwin
->frame
->core
);
1475 wSetFocusTo(scr
, thePanel
->wwin
);
1480 panel
= wmalloc(sizeof(InfoPanel
));
1481 memset(panel
, 0, sizeof(InfoPanel
));
1485 panel
->win
= WMCreateWindow(scr
->wmscreen
, "info");
1486 WMResizeWidget(panel
->win
, 390, 230);
1488 logo
= WMCreateApplicationIconBlendedPixmap(scr
->wmscreen
, (RColor
*) NULL
);
1490 logo
= WMRetainPixmap(WMGetApplicationIconPixmap(scr
->wmscreen
));
1493 size
= WMGetPixmapSize(logo
);
1494 panel
->logoL
= WMCreateLabel(panel
->win
);
1495 WMResizeWidget(panel
->logoL
, 64, 64);
1496 WMMoveWidget(panel
->logoL
, 30, 20);
1497 WMSetLabelImagePosition(panel
->logoL
, WIPImageOnly
);
1498 WMSetLabelImage(panel
->logoL
, logo
);
1500 WMCreateEventHandler(WMWidgetView(panel
->logoL
), ButtonPressMask
, handleLogoPush
, panel
);
1502 WMReleasePixmap(logo
);
1506 panel
->name1L
= WMCreateLabel(panel
->win
);
1507 WMResizeWidget(panel
->name1L
, 240, 30 + 2);
1508 WMMoveWidget(panel
->name1L
, 100, 30 - 2 - sepHeight
);
1510 name
= "Lucida Sans,Comic Sans MS,URW Gothic L,Trebuchet MS" ":italic:pixelsize=28:antialias=true";
1511 font
= WMCreateFont(scr
->wmscreen
, name
);
1512 strbuf
= "Window Maker";
1514 width
= WMWidthOfString(font
, strbuf
, strlen(strbuf
));
1515 WMSetLabelFont(panel
->name1L
, font
);
1516 WMReleaseFont(font
);
1518 WMSetLabelTextAlignment(panel
->name1L
, WACenter
);
1519 WMSetLabelText(panel
->name1L
, strbuf
);
1521 panel
->lineF
= WMCreateFrame(panel
->win
);
1522 WMResizeWidget(panel
->lineF
, width
, sepHeight
);
1523 WMMoveWidget(panel
->lineF
, 100 + (240 - width
) / 2, 60 - sepHeight
);
1524 WMSetFrameRelief(panel
->lineF
, WRSimple
);
1525 WMSetWidgetBackgroundColor(panel
->lineF
, scr
->black
);
1527 panel
->name2L
= WMCreateLabel(panel
->win
);
1528 WMResizeWidget(panel
->name2L
, 240, 24);
1529 WMMoveWidget(panel
->name2L
, 100, 60);
1530 name
= "URW Gothic L,Nimbus Sans L:pixelsize=16:antialias=true";
1531 font
= WMCreateFont(scr
->wmscreen
, name
);
1533 WMSetLabelFont(panel
->name2L
, font
);
1534 WMReleaseFont(font
);
1537 WMSetLabelTextAlignment(panel
->name2L
, WACenter
);
1538 WMSetLabelText(panel
->name2L
, _("Window Manager for X"));
1540 snprintf(buffer
, sizeof(buffer
), _("Version %s"), VERSION
);
1541 panel
->versionL
= WMCreateLabel(panel
->win
);
1542 WMResizeWidget(panel
->versionL
, 310, 16);
1543 WMMoveWidget(panel
->versionL
, 30, 95);
1544 WMSetLabelTextAlignment(panel
->versionL
, WARight
);
1545 WMSetLabelText(panel
->versionL
, buffer
);
1546 WMSetLabelWraps(panel
->versionL
, False
);
1548 panel
->copyrL
= WMCreateLabel(panel
->win
);
1549 WMResizeWidget(panel
->copyrL
, 360, 40);
1550 WMMoveWidget(panel
->copyrL
, 15, 185);
1551 WMSetLabelTextAlignment(panel
->copyrL
, WALeft
);
1552 WMSetLabelText(panel
->copyrL
, COPYRIGHT_TEXT
);
1553 font
= WMSystemFontOfSize(scr
->wmscreen
, 11);
1555 WMSetLabelFont(panel
->copyrL
, font
);
1556 WMReleaseFont(font
);
1561 snprintf(buffer
, sizeof(buffer
), _("Using visual 0x%x: %s %ibpp "),
1562 (unsigned)scr
->w_visual
->visualid
, visuals
[scr
->w_visual
->class], scr
->w_depth
);
1564 strbuf
= wstrappend(strbuf
, buffer
);
1566 switch (scr
->w_depth
) {
1568 strbuf
= wstrappend(strbuf
, _("(32 thousand colors)\n"));
1571 strbuf
= wstrappend(strbuf
, _("(64 thousand colors)\n"));
1575 strbuf
= wstrappend(strbuf
, _("(16 million colors)\n"));
1578 snprintf(buffer
, sizeof(buffer
), _("(%d colors)\n"), 1 << scr
->w_depth
);
1579 strbuf
= wstrappend(strbuf
, buffer
);
1583 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
1585 struct mallinfo ma
= mallinfo();
1586 snprintf(buffer
, sizeof(buffer
),
1587 _("Total allocated memory: %i kB. Total memory in use: %i kB.\n"),
1588 (ma
.arena
+ ma
.hblkhd
) / 1024, (ma
.uordblks
+ ma
.hblkhd
) / 1024);
1590 strbuf
= wstrappend(strbuf
, buffer
);
1594 strbuf
= wstrappend(strbuf
, _("Supported image formats: "));
1595 strl
= RSupportedFileFormats();
1596 for (i
= 0; strl
[i
] != NULL
; i
++) {
1597 strbuf
= wstrappend(strbuf
, strl
[i
]);
1598 strbuf
= wstrappend(strbuf
, " ");
1601 strbuf
= wstrappend(strbuf
, _("\nAdditional support for: "));
1608 list
[j
++] = "WMSPEC";
1615 for (i
= 0; i
< j
; i
++) {
1618 strcat(buf
, _(" and "));
1622 strcat(buf
, list
[i
]);
1624 strbuf
= wstrappend(strbuf
, buf
);
1627 #ifdef VIRTUAL_DESKTOP
1628 if (wPreferences
.vdesk_enable
)
1629 strbuf
= wstrappend(strbuf
, _(", VirtualDesktop enabled"));
1631 strbuf
= wstrappend(strbuf
, _(", VirtualDesktop disabled"));
1635 strbuf
= wstrappend(strbuf
, _("\n"));
1636 #ifdef SOLARIS_XINERAMA
1637 strbuf
= wstrappend(strbuf
, _("Solaris "));
1639 strbuf
= wstrappend(strbuf
, _("Xinerama: "));
1642 snprintf(tmp
, sizeof(tmp
) - 1, "%d heads found.", scr
->xine_info
.count
);
1643 strbuf
= wstrappend(strbuf
, tmp
);
1647 panel
->infoL
= WMCreateLabel(panel
->win
);
1648 WMResizeWidget(panel
->infoL
, 350, 75);
1649 WMMoveWidget(panel
->infoL
, 15, 115);
1650 WMSetLabelText(panel
->infoL
, strbuf
);
1651 font
= WMSystemFontOfSize(scr
->wmscreen
, 11);
1653 WMSetLabelFont(panel
->infoL
, font
);
1654 WMReleaseFont(font
);
1659 WMRealizeWidget(panel
->win
);
1660 WMMapSubwidgets(panel
->win
);
1662 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 382, 230, 0, 0, 0);
1664 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
1666 WMMapWidget(panel
->win
);
1669 WMPoint center
= getCenter(scr
, 382, 230);
1671 wwin
= wManageInternalWindow(scr
, parent
, None
, _("Info"), center
.x
, center
.y
, 382, 230);
1674 WSETUFLAG(wwin
, no_closable
, 0);
1675 WSETUFLAG(wwin
, no_close_button
, 0);
1676 #ifdef XKB_BUTTON_HINT
1677 wFrameWindowHideButton(wwin
->frame
, WFF_LANGUAGE_BUTTON
);
1679 wWindowUpdateButtonImages(wwin
);
1680 wFrameWindowShowButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1681 wwin
->frame
->on_click_right
= destroyInfoPanel
;
1689 if (InitXThing(panel
->scr
)) {
1690 panel
->timer
= WMAddTimerHandler(100, logoPushCallback
, panel
);
1693 panel
->str
= _("Merry Christmas!");
1694 panel
->oldPix
= WMRetainPixmap(WMGetLabelImage(panel
->logoL
));
1700 ***********************************************************************
1702 ***********************************************************************
1715 static LegalPanel
*legalPanel
= NULL
;
1717 static void destroyLegalPanel(WCoreWindow
* foo
, void *data
, XEvent
* event
)
1719 WMUnmapWidget(legalPanel
->win
);
1721 WMDestroyWidget(legalPanel
->win
);
1723 wUnmanageWindow(legalPanel
->wwin
, False
, False
);
1730 void wShowLegalPanel(WScreen
* scr
)
1737 if (legalPanel
->scr
== scr
) {
1738 wRaiseFrame(legalPanel
->wwin
->frame
->core
);
1739 wSetFocusTo(scr
, legalPanel
->wwin
);
1744 panel
= wmalloc(sizeof(LegalPanel
));
1748 panel
->win
= WMCreateWindow(scr
->wmscreen
, "legal");
1749 WMResizeWidget(panel
->win
, 420, 250);
1751 panel
->licenseL
= WMCreateLabel(panel
->win
);
1752 WMSetLabelWraps(panel
->licenseL
, True
);
1753 WMResizeWidget(panel
->licenseL
, 400, 230);
1754 WMMoveWidget(panel
->licenseL
, 10, 10);
1755 WMSetLabelTextAlignment(panel
->licenseL
, WALeft
);
1756 WMSetLabelText(panel
->licenseL
,
1757 _(" Window Maker is free software; you can redistribute it and/or\n"
1758 "modify it under the terms of the GNU General Public License as\n"
1759 "published by the Free Software Foundation; either version 2 of the\n"
1760 "License, or (at your option) any later version.\n\n"
1761 " Window Maker is distributed in the hope that it will be useful,\n"
1762 "but WITHOUT ANY WARRANTY; without even the implied warranty\n"
1763 "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
1764 "See the GNU General Public License for more details.\n\n"
1765 " You should have received a copy of the GNU General Public\n"
1766 "License along with this program; if not, write to the Free Software\n"
1767 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\n" "02111-1307, USA."));
1768 WMSetLabelRelief(panel
->licenseL
, WRGroove
);
1770 WMRealizeWidget(panel
->win
);
1771 WMMapSubwidgets(panel
->win
);
1773 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 420, 250, 0, 0, 0);
1775 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
1778 WMPoint center
= getCenter(scr
, 420, 250);
1780 wwin
= wManageInternalWindow(scr
, parent
, None
, _("Legal"), center
.x
, center
.y
, 420, 250);
1783 WSETUFLAG(wwin
, no_closable
, 0);
1784 WSETUFLAG(wwin
, no_close_button
, 0);
1785 wWindowUpdateButtonImages(wwin
);
1786 wFrameWindowShowButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1787 #ifdef XKB_BUTTON_HINT
1788 wFrameWindowHideButton(wwin
->frame
, WFF_LANGUAGE_BUTTON
);
1790 wwin
->frame
->on_click_right
= destroyLegalPanel
;
1794 WMMapWidget(panel
->win
);
1802 ***********************************************************************
1803 * Crashing Dialog Panel
1804 ***********************************************************************
1807 extern WDDomain
*WDWindowAttributes
;
1809 typedef struct _CrashPanel
{
1810 WMWindow
*win
; /* main window */
1812 WMLabel
*iconL
; /* application icon */
1813 WMLabel
*nameL
; /* title of panel */
1815 WMFrame
*sepF
; /* separator frame */
1817 WMLabel
*noteL
; /* Title of note */
1818 WMLabel
*note2L
; /* body of note with what happened */
1820 WMFrame
*whatF
; /* "what to do next" frame */
1821 WMPopUpButton
*whatP
; /* action selection popup button */
1823 WMButton
*okB
; /* ok button */
1825 Bool done
; /* if finished with this dialog */
1826 int action
; /* what to do after */
1832 static void handleKeyPress(XEvent
* event
, void *clientData
)
1834 CrashPanel
*panel
= (CrashPanel
*) clientData
;
1836 if (event
->xkey
.keycode
== panel
->retKey
) {
1837 WMPerformButtonClick(panel
->okB
);
1841 static void okButtonCallback(void *self
, void *clientData
)
1843 CrashPanel
*panel
= (CrashPanel
*) clientData
;
1848 static void setCrashAction(void *self
, void *clientData
)
1850 WMPopUpButton
*pop
= (WMPopUpButton
*) self
;
1851 CrashPanel
*panel
= (CrashPanel
*) clientData
;
1853 panel
->action
= WMGetPopUpButtonSelectedItem(pop
);
1856 /* Make this read the logo from a compiled in pixmap -Dan */
1857 static WMPixmap
*getWindowMakerIconImage(WMScreen
* scr
)
1859 WMPropList
*dict
, *key
, *option
, *value
= NULL
;
1860 WMPixmap
*pix
= NULL
;
1863 if (!WDWindowAttributes
|| !WDWindowAttributes
->dictionary
)
1866 WMPLSetCaseSensitive(True
);
1868 key
= WMCreatePLString("Logo.WMPanel");
1869 option
= WMCreatePLString("Icon");
1871 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
1874 value
= WMGetFromPLDictionary(dict
, option
);
1877 WMReleasePropList(key
);
1878 WMReleasePropList(option
);
1880 WMPLSetCaseSensitive(False
);
1882 if (value
&& WMIsPLString(value
)) {
1883 path
= FindImage(wPreferences
.icon_path
, WMGetFromPLString(value
));
1893 pix
= WMCreateBlendedPixmapFromFile(scr
, path
, &gray
);
1904 int wShowCrashingDialogPanel(int whatSig
)
1910 int screen_no
, scr_width
, scr_height
;
1914 panel
= wmalloc(sizeof(CrashPanel
));
1915 memset(panel
, 0, sizeof(CrashPanel
));
1917 screen_no
= DefaultScreen(dpy
);
1918 scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_no
));
1919 scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_no
));
1921 scr
= WMCreateScreen(dpy
, screen_no
);
1923 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
1927 panel
->retKey
= XKeysymToKeycode(dpy
, XK_Return
);
1929 panel
->win
= WMCreateWindow(scr
, "crashingDialog");
1930 WMResizeWidget(panel
->win
, PWIDTH
, PHEIGHT
);
1931 WMMoveWidget(panel
->win
, (scr_width
- PWIDTH
) / 2, (scr_height
- PHEIGHT
) / 2);
1933 logo
= getWindowMakerIconImage(scr
);
1935 panel
->iconL
= WMCreateLabel(panel
->win
);
1936 WMResizeWidget(panel
->iconL
, 64, 64);
1937 WMMoveWidget(panel
->iconL
, 10, 10);
1938 WMSetLabelImagePosition(panel
->iconL
, WIPImageOnly
);
1939 WMSetLabelImage(panel
->iconL
, logo
);
1942 panel
->nameL
= WMCreateLabel(panel
->win
);
1943 WMResizeWidget(panel
->nameL
, 200, 30);
1944 WMMoveWidget(panel
->nameL
, 80, 25);
1945 WMSetLabelTextAlignment(panel
->nameL
, WALeft
);
1946 font
= WMBoldSystemFontOfSize(scr
, 24);
1947 WMSetLabelFont(panel
->nameL
, font
);
1948 WMReleaseFont(font
);
1949 WMSetLabelText(panel
->nameL
, _("Fatal error"));
1951 panel
->sepF
= WMCreateFrame(panel
->win
);
1952 WMResizeWidget(panel
->sepF
, PWIDTH
+ 4, 2);
1953 WMMoveWidget(panel
->sepF
, -2, 80);
1955 panel
->noteL
= WMCreateLabel(panel
->win
);
1956 WMResizeWidget(panel
->noteL
, PWIDTH
- 20, 40);
1957 WMMoveWidget(panel
->noteL
, 10, 90);
1958 WMSetLabelTextAlignment(panel
->noteL
, WAJustified
);
1959 #ifdef SYS_SIGLIST_DECLARED
1960 snprintf(buf
, sizeof(buf
), _("Window Maker received signal %i\n(%s)."), whatSig
, sys_siglist
[whatSig
]);
1962 snprintf(buf
, sizeof(buf
), _("Window Maker received signal %i."), whatSig
);
1964 WMSetLabelText(panel
->noteL
, buf
);
1966 panel
->note2L
= WMCreateLabel(panel
->win
);
1967 WMResizeWidget(panel
->note2L
, PWIDTH
- 20, 100);
1968 WMMoveWidget(panel
->note2L
, 10, 130);
1969 WMSetLabelTextAlignment(panel
->note2L
, WALeft
);
1970 WMSetLabelText(panel
->note2L
,
1971 _(" This fatal error occured probably due to a bug."
1972 " Please fill the included BUGFORM and " "report it to bugs@windowmaker.info."));
1973 WMSetLabelWraps(panel
->note2L
, True
);
1975 panel
->whatF
= WMCreateFrame(panel
->win
);
1976 WMResizeWidget(panel
->whatF
, PWIDTH
- 20, 50);
1977 WMMoveWidget(panel
->whatF
, 10, 240);
1978 WMSetFrameTitle(panel
->whatF
, _("What do you want to do now?"));
1980 panel
->whatP
= WMCreatePopUpButton(panel
->whatF
);
1981 WMResizeWidget(panel
->whatP
, PWIDTH
- 20 - 70, 20);
1982 WMMoveWidget(panel
->whatP
, 35, 20);
1983 WMSetPopUpButtonPullsDown(panel
->whatP
, False
);
1984 WMSetPopUpButtonText(panel
->whatP
, _("Select action"));
1985 WMAddPopUpButtonItem(panel
->whatP
, _("Abort and leave a core file"));
1986 WMAddPopUpButtonItem(panel
->whatP
, _("Restart Window Maker"));
1987 WMAddPopUpButtonItem(panel
->whatP
, _("Start alternate window manager"));
1988 WMSetPopUpButtonAction(panel
->whatP
, setCrashAction
, panel
);
1989 WMSetPopUpButtonSelectedItem(panel
->whatP
, WMRestart
);
1990 panel
->action
= WMRestart
;
1992 WMMapSubwidgets(panel
->whatF
);
1994 panel
->okB
= WMCreateCommandButton(panel
->win
);
1995 WMResizeWidget(panel
->okB
, 80, 26);
1996 WMMoveWidget(panel
->okB
, 205, 309);
1997 WMSetButtonText(panel
->okB
, _("OK"));
1998 WMSetButtonImage(panel
->okB
, WMGetSystemPixmap(scr
, WSIReturnArrow
));
1999 WMSetButtonAltImage(panel
->okB
, WMGetSystemPixmap(scr
, WSIHighlightedReturnArrow
));
2000 WMSetButtonImagePosition(panel
->okB
, WIPRight
);
2001 WMSetButtonAction(panel
->okB
, okButtonCallback
, panel
);
2005 WMCreateEventHandler(WMWidgetView(panel
->win
), KeyPressMask
, handleKeyPress
, panel
);
2007 WMRealizeWidget(panel
->win
);
2008 WMMapSubwidgets(panel
->win
);
2010 WMMapWidget(panel
->win
);
2012 XSetInputFocus(dpy
, WMWidgetXID(panel
->win
), RevertToParent
, CurrentTime
);
2014 while (!panel
->done
) {
2017 WMNextEvent(dpy
, &event
);
2018 WMHandleEvent(&event
);
2021 action
= panel
->action
;
2023 WMUnmapWidget(panel
->win
);
2024 WMDestroyWidget(panel
->win
);
2030 /*****************************************************************************
2031 * About GNUstep Panel
2032 *****************************************************************************/
2035 drawGNUstepLogo(Display
* dpy
, Drawable d
, int width
, int height
,
2036 unsigned long blackPixel
, unsigned long whitePixel
)
2040 XRectangle rects
[3];
2042 gcv
.foreground
= blackPixel
;
2043 gc
= XCreateGC(dpy
, d
, GCForeground
, &gcv
);
2045 XFillArc(dpy
, d
, gc
, width
/ 45, height
/ 45,
2046 width
- 2 * width
/ 45, height
- 2 * height
/ 45, 0, 360 * 64);
2049 rects
[0].y
= 37 * height
/ 45;
2050 rects
[0].width
= width
/ 3;
2051 rects
[0].height
= height
- rects
[0].y
;
2053 rects
[1].x
= rects
[0].width
;
2054 rects
[1].y
= height
/ 2;
2055 rects
[1].width
= width
- 2 * width
/ 3;
2056 rects
[1].height
= height
- rects
[1].y
;
2058 rects
[2].x
= 2 * width
/ 3;
2059 rects
[2].y
= height
- 37 * height
/ 45;
2060 rects
[2].width
= width
/ 3;
2061 rects
[2].height
= height
- rects
[2].y
;
2063 XSetClipRectangles(dpy
, gc
, 0, 0, rects
, 3, Unsorted
);
2064 XFillRectangle(dpy
, d
, gc
, 0, 0, width
, height
);
2066 XSetForeground(dpy
, gc
, whitePixel
);
2067 XFillArc(dpy
, d
, gc
, width
/ 45, height
/ 45,
2068 width
- 2 * width
/ 45, height
- 2 * height
/ 45, 0, 360 * 64);
2084 static GNUstepPanel
*gnustepPanel
= NULL
;
2086 static void destroyGNUstepPanel(WCoreWindow
* foo
, void *data
, XEvent
* event
)
2088 WMUnmapWidget(gnustepPanel
->win
);
2090 WMDestroyWidget(gnustepPanel
->win
);
2092 wUnmanageWindow(gnustepPanel
->wwin
, False
, False
);
2094 wfree(gnustepPanel
);
2096 gnustepPanel
= NULL
;
2099 void wShowGNUstepPanel(WScreen
* scr
)
2101 GNUstepPanel
*panel
;
2108 if (gnustepPanel
->scr
== scr
) {
2109 wRaiseFrame(gnustepPanel
->wwin
->frame
->core
);
2110 wSetFocusTo(scr
, gnustepPanel
->wwin
);
2115 panel
= wmalloc(sizeof(GNUstepPanel
));
2119 panel
->win
= WMCreateWindow(scr
->wmscreen
, "About GNUstep");
2120 WMResizeWidget(panel
->win
, 325, 205);
2122 pixmap
= WMCreatePixmap(scr
->wmscreen
, 130, 130, WMScreenDepth(scr
->wmscreen
), True
);
2124 color
= WMCreateNamedColor(scr
->wmscreen
, "gray50", True
);
2126 drawGNUstepLogo(dpy
, WMGetPixmapXID(pixmap
), 130, 130, WMColorPixel(color
), scr
->white_pixel
);
2128 WMReleaseColor(color
);
2130 XSetForeground(dpy
, scr
->mono_gc
, 0);
2131 XFillRectangle(dpy
, WMGetPixmapMaskXID(pixmap
), scr
->mono_gc
, 0, 0, 130, 130);
2132 drawGNUstepLogo(dpy
, WMGetPixmapMaskXID(pixmap
), 130, 130, 1, 1);
2134 panel
->gstepL
= WMCreateLabel(panel
->win
);
2135 WMResizeWidget(panel
->gstepL
, 285, 64);
2136 WMMoveWidget(panel
->gstepL
, 20, 0);
2137 WMSetLabelTextAlignment(panel
->gstepL
, WARight
);
2138 WMSetLabelText(panel
->gstepL
, "GNUstep");
2140 WMFont
*font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 24);
2142 WMSetLabelFont(panel
->gstepL
, font
);
2143 WMReleaseFont(font
);
2146 panel
->textL
= WMCreateLabel(panel
->win
);
2147 WMResizeWidget(panel
->textL
, 305, 140);
2148 WMMoveWidget(panel
->textL
, 10, 50);
2149 WMSetLabelTextAlignment(panel
->textL
, WARight
);
2150 WMSetLabelImagePosition(panel
->textL
, WIPOverlaps
);
2151 WMSetLabelText(panel
->textL
,
2152 _("Window Maker is part of the GNUstep project.\n"
2153 "The GNUstep project aims to create a free\n"
2154 "implementation of the OpenStep(tm) specification\n"
2155 "which is a object-oriented framework for\n"
2156 "creating advanced graphical, multi-platform\n"
2157 "applications. Additionally, a development and\n"
2158 "user desktop enviroment will be created on top\n"
2159 "of the framework. For more information about\n"
2160 "GNUstep, please visit: www.gnustep.org"));
2161 WMSetLabelImage(panel
->textL
, pixmap
);
2163 WMReleasePixmap(pixmap
);
2165 WMRealizeWidget(panel
->win
);
2166 WMMapSubwidgets(panel
->win
);
2168 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 325, 200, 0, 0, 0);
2170 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
2173 WMPoint center
= getCenter(scr
, 325, 200);
2175 wwin
= wManageInternalWindow(scr
, parent
, None
, _("About GNUstep"), center
.x
, center
.y
, 325, 200);
2178 WSETUFLAG(wwin
, no_closable
, 0);
2179 WSETUFLAG(wwin
, no_close_button
, 0);
2180 wWindowUpdateButtonImages(wwin
);
2181 wFrameWindowShowButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
2182 #ifdef XKB_BUTTON_HINT
2183 wFrameWindowHideButton(wwin
->frame
, WFF_LANGUAGE_BUTTON
);
2185 wwin
->frame
->on_click_right
= destroyGNUstepPanel
;
2189 WMMapWidget(panel
->win
);
2193 gnustepPanel
= panel
;