9 typedef struct W_Window
{
13 struct W_Window
*nextPtr
; /* next in the window list */
15 struct W_Window
*owner
;
19 WMPixmap
*miniImage
; /* miniwindow */
24 WMSize resizeIncrement
;
34 WMAction
*closeAction
;
41 unsigned configured
:1;
42 unsigned documentEdited
:1;
57 Pixmap miniaturize_pixmap
; /* pixmap for miniaturize button */
58 Pixmap close_pixmap
; /* pixmap for close button */
59 Pixmap miniaturize_mask
; /* miniaturize pixmap mask */
60 Pixmap close_mask
; /* close pixmap mask */
62 } GNUstepWMAttributes
;
64 #define GSWindowStyleAttr (1<<0)
65 #define GSWindowLevelAttr (1<<1)
66 #define GSMiniaturizePixmapAttr (1<<3)
67 #define GSClosePixmapAttr (1<<4)
68 #define GSMiniaturizeMaskAttr (1<<5)
69 #define GSCloseMaskAttr (1<<6)
70 #define GSExtraFlagsAttr (1<<7)
73 #define GSDocumentEditedFlag (1<<0)
74 #define GSNoApplicationIconFlag (1<<5)
76 #define WMFHideOtherApplications 10
77 #define WMFHideApplication 12
81 static void willResizeWindow(W_ViewDelegate
*, WMView
*, unsigned*, unsigned*);
83 struct W_ViewDelegate _WindowViewDelegate
= {
92 #define DEFAULT_WIDTH 400
93 #define DEFAULT_HEIGHT 180
94 #define DEFAULT_TITLE ""
97 static void destroyWindow(_Window
*win
);
99 static void handleEvents();
101 static void realizeWindow();
104 realizeObserver(void *self
, WMNotification
*not)
111 WMCreatePanelWithStyleForWindow(WMWindow
*owner
, char *name
, int style
)
115 win
= WMCreateWindowWithStyle(owner
->view
->screen
, name
, style
);
124 WMCreatePanelForWindow(WMWindow
*owner
, char *name
)
126 return WMCreatePanelWithStyleForWindow(owner
, name
,
128 |WMClosableWindowMask
129 |WMResizableWindowMask
);
134 WMChangePanelOwner(WMWindow
*win
, WMWindow
*newOwner
)
136 win
->owner
= newOwner
;
138 if (win
->view
->flags
.realized
&& newOwner
) {
139 XSetTransientForHint(win
->view
->screen
->display
, win
->view
->window
,
140 newOwner
->view
->window
);
147 WMCreateWindow(WMScreen
*screen
, char *name
)
149 return WMCreateWindowWithStyle(screen
, name
, WMTitledWindowMask
150 |WMClosableWindowMask
151 |WMMiniaturizableWindowMask
152 |WMResizableWindowMask
);
158 WMCreateWindowWithStyle(WMScreen
*screen
, char *name
, int style
)
162 win
= wmalloc(sizeof(_Window
));
163 memset(win
, 0, sizeof(_Window
));
165 win
->widgetClass
= WC_Window
;
167 win
->view
= W_CreateTopView(screen
);
172 win
->view
->self
= win
;
174 win
->view
->delegate
= &_WindowViewDelegate
;
176 win
->wname
= wstrdup(name
);
178 /* add to the window list of the screen (application) */
179 win
->nextPtr
= screen
->windowList
;
180 screen
->windowList
= win
;
182 WMCreateEventHandler(win
->view
, ExposureMask
|StructureNotifyMask
183 |ClientMessageMask
|FocusChangeMask
,
186 W_ResizeView(win
->view
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
188 WMAddNotificationObserver(realizeObserver
, win
,
189 WMViewRealizedNotification
, win
->view
);
191 win
->flags
.style
= style
;
193 win
->level
= WMNormalWindowLevel
;
195 /* kluge. Find a better solution */
196 W_SetFocusOfTopLevel(win
->view
, win
->view
);
204 setWindowTitle(WMWindow
*win
, const char *title
)
206 WMScreen
*scr
= win
->view
->screen
;
207 XTextProperty property
;
210 result
= XmbTextListToTextProperty(scr
->display
,
211 (char**)&title
, 1, XStdICCTextStyle
,
213 if (result
== XNoMemory
|| result
== XLocaleNotSupported
) {
214 wwarning("window title conversion error... using STRING encoding");
215 XStoreName(scr
->display
, win
->view
->window
, title
);
217 XSetWMName(scr
->display
, win
->view
->window
, &property
);
219 XFree(property
.value
);
222 XChangeProperty(scr
->display
, win
->view
->window
,
223 scr
->netwmName
, scr
->utf8String
, 8,
224 PropModeReplace
, (unsigned char *)title
, strlen(title
));
229 setMiniwindowTitle(WMWindow
*win
, const char *title
)
231 WMScreen
*scr
= win
->view
->screen
;
232 XTextProperty property
;
235 result
= XmbTextListToTextProperty(scr
->display
,
236 (char**)&title
, 1, XStdICCTextStyle
,
238 if (result
== XNoMemory
|| result
== XLocaleNotSupported
) {
239 wwarning("icon title conversion error..using STRING encoding");
240 XSetIconName(scr
->display
, win
->view
->window
, title
);
242 XSetWMIconName(scr
->display
, win
->view
->window
, &property
);
244 XFree(property
.value
);
247 XChangeProperty(scr
->display
, win
->view
->window
,
248 scr
->netwmIconName
, scr
->utf8String
, 8,
249 PropModeReplace
, (unsigned char *)title
, strlen(title
));
254 setMiniwindow(WMWindow
*win
, RImage
*image
)
256 WMScreen
*scr
= win
->view
->screen
;
264 data
= malloc((image
->width
* image
->height
+ 2) * sizeof(CARD32
));
269 data
[o
++] = image
->width
;
270 data
[o
++] = image
->height
;
272 for (y
= 0; y
< image
->height
; y
++) {
273 for (x
= 0; x
< image
->width
; x
++) {
275 int offs
= (x
+y
*image
->width
);
277 if (image
->format
== RRGBFormat
)
278 pixel
= image
->data
[offs
*3]<<16 | image
->data
[offs
*3+1]<<8 | image
->data
[offs
*3+2];
280 pixel
= image
->data
[offs
*4]<<16 | image
->data
[offs
*4+1]<<8 | image
->data
[offs
*4+2] | image
->data
[offs
*4+3] << 24;
286 XChangeProperty(scr
->display
, win
->view
->window
,
287 scr
->netwmIcon
, XA_CARDINAL
, 32,
289 (unsigned char *)data
,
290 (image
->width
* image
->height
+ 2) * sizeof(CARD32
));
297 WMSetWindowTitle(WMWindow
*win
, char *title
)
299 if (win
->title
!=NULL
)
302 win
->title
= wstrdup(title
);
306 if (win
->view
->flags
.realized
) {
307 setWindowTitle(win
, title
);
315 WMSetWindowCloseAction(WMWindow
*win
, WMAction
*action
, void *clientData
)
320 WMScreen
*scr
= win
->view
->screen
;
322 if (win
->view
->flags
.realized
) {
323 if (action
&& !win
->closeAction
) {
324 if (!XGetWMProtocols(scr
->display
, win
->view
->window
, &atoms
,
328 newAtoms
= wmalloc((count
+1)*sizeof(Atom
));
330 memcpy(newAtoms
, atoms
, count
*sizeof(Atom
));
331 newAtoms
[count
++] = scr
->deleteWindowAtom
;
332 XSetWMProtocols(scr
->display
, win
->view
->window
, newAtoms
, count
);
336 } else if (!action
&& win
->closeAction
) {
339 if (XGetWMProtocols(scr
->display
, win
->view
->window
, &atoms
,
340 &count
) && count
>0) {
341 newAtoms
= wmalloc((count
-1)*sizeof(Atom
));
343 for (i
=0; i
< count
; i
++) {
344 if (atoms
[i
]!=scr
->deleteWindowAtom
) {
345 newAtoms
[i
] = atoms
[i
];
349 XSetWMProtocols(scr
->display
, win
->view
->window
, newAtoms
,
357 win
->closeAction
= action
;
358 win
->closeData
= clientData
;
364 willResizeWindow(W_ViewDelegate
*self
, WMView
*view
,
365 unsigned *width
, unsigned *height
)
367 WMWindow
*win
= (WMWindow
*)view
->self
;
369 if (win
->minSize
.width
> 0 && win
->minSize
.height
> 0) {
370 if (*width
< win
->minSize
.width
)
371 *width
= win
->minSize
.width
;
372 if (*height
< win
->minSize
.height
)
373 *height
= win
->minSize
.height
;
376 if (win
->maxSize
.width
> 0 && win
->maxSize
.height
> 0) {
377 if (*width
> win
->maxSize
.width
)
378 *width
= win
->maxSize
.width
;
379 if (*height
> win
->maxSize
.height
)
380 *height
= win
->maxSize
.height
;
386 setSizeHints(WMWindow
*win
)
390 hints
= XAllocSizeHints();
392 wwarning("could not allocate memory for window size hints");
398 if (win
->flags
.setPPos
) {
399 hints
->flags
|= PPosition
;
400 hints
->x
= win
->ppos
.x
;
401 hints
->y
= win
->ppos
.y
;
403 if (win
->flags
.setUPos
) {
404 hints
->flags
|= USPosition
;
405 hints
->x
= win
->upos
.x
;
406 hints
->y
= win
->upos
.y
;
408 if (win
->minSize
.width
>0 && win
->minSize
.height
>0) {
409 hints
->flags
|= PMinSize
;
410 hints
->min_width
= win
->minSize
.width
;
411 hints
->min_height
= win
->minSize
.height
;
413 if (win
->maxSize
.width
>0 && win
->maxSize
.height
>0) {
414 hints
->flags
|= PMaxSize
;
415 hints
->max_width
= win
->maxSize
.width
;
416 hints
->max_height
= win
->maxSize
.height
;
418 if (win
->baseSize
.width
>0 && win
->baseSize
.height
>0) {
419 hints
->flags
|= PBaseSize
;
420 hints
->base_width
= win
->baseSize
.width
;
421 hints
->base_height
= win
->baseSize
.height
;
423 if (win
->resizeIncrement
.width
>0 && win
->resizeIncrement
.height
>0) {
424 hints
->flags
|= PResizeInc
;
425 hints
->width_inc
= win
->resizeIncrement
.width
;
426 hints
->height_inc
= win
->resizeIncrement
.height
;
428 if (win
->flags
.setAspect
) {
429 hints
->flags
|= PAspect
;
430 hints
->min_aspect
.x
= win
->minAspect
.x
;
431 hints
->min_aspect
.y
= win
->minAspect
.y
;
432 hints
->max_aspect
.x
= win
->maxAspect
.x
;
433 hints
->max_aspect
.y
= win
->maxAspect
.y
;
438 XSetWMNormalHints(win
->view
->screen
->display
, win
->view
->window
, hints
);
446 writeGNUstepWMAttr(WMScreen
*scr
, Window window
, GNUstepWMAttributes
*attr
)
448 unsigned long data
[9];
450 /* handle idiot compilers where array of CARD32 != struct of CARD32 */
451 data
[0] = attr
->flags
;
452 data
[1] = attr
->window_style
;
453 data
[2] = attr
->window_level
;
454 data
[3] = 0; /* reserved */
455 /* The X protocol says XIDs are 32bit */
456 data
[4] = attr
->miniaturize_pixmap
;
457 data
[5] = attr
->close_pixmap
;
458 data
[6] = attr
->miniaturize_mask
;
459 data
[7] = attr
->close_mask
;
460 data
[8] = attr
->extra_flags
;
461 XChangeProperty(scr
->display
, window
, scr
->attribsAtom
, scr
->attribsAtom
,
462 32, PropModeReplace
, (unsigned char *)data
, 9);
467 setWindowMakerHints(WMWindow
*win
)
469 GNUstepWMAttributes attribs
;
470 WMScreen
*scr
= WMWidgetScreen(win
);
472 memset(&attribs
, 0, sizeof(GNUstepWMAttributes
));
473 attribs
.flags
= GSWindowStyleAttr
|GSWindowLevelAttr
|GSExtraFlagsAttr
;
474 attribs
.window_style
= win
->flags
.style
;
475 attribs
.window_level
= win
->level
;
476 if (win
->flags
.documentEdited
)
477 attribs
.extra_flags
= GSDocumentEditedFlag
;
479 attribs
.extra_flags
= 0;
481 writeGNUstepWMAttr(scr
, win
->view
->window
, &attribs
);
486 realizeWindow(WMWindow
*win
)
489 XClassHint
*classHint
;
490 WMScreen
*scr
= win
->view
->screen
;
494 classHint
= XAllocClassHint();
495 classHint
->res_name
= win
->wname
;
496 classHint
->res_class
= WMGetApplicationName();
497 XSetClassHint(scr
->display
, win
->view
->window
, classHint
);
500 hints
= XAllocWMHints();
502 if (!scr
->aflags
.simpleApplication
) {
503 hints
->flags
|= WindowGroupHint
;
504 hints
->window_group
= scr
->groupLeader
;
506 if (win
->miniImage
) {
507 hints
->flags
|= IconPixmapHint
;
508 hints
->icon_pixmap
= WMGetPixmapXID(win
->miniImage
);
509 hints
->icon_mask
= WMGetPixmapMaskXID(win
->miniImage
);
510 if (hints
->icon_mask
!= None
) {
511 hints
->flags
|= IconMaskHint
;
514 if (hints
->flags
!= 0)
515 XSetWMHints(scr
->display
, win
->view
->window
, hints
);
519 if (win
->closeAction
) {
520 atoms
[count
++] = scr
->deleteWindowAtom
;
524 XSetWMProtocols(scr
->display
, win
->view
->window
, atoms
, count
);
526 if (win
->title
|| win
->miniTitle
)
527 XmbSetWMProperties(scr
->display
, win
->view
->window
, win
->title
,
528 win
->miniTitle
, NULL
, 0, NULL
, NULL
, NULL
);
530 setWindowMakerHints(win
);
535 XSetTransientForHint(scr
->display
, win
->view
->window
,
536 win
->owner
->view
->window
);
540 setWindowTitle(win
, win
->title
);
546 WMSetWindowAspectRatio(WMWindow
*win
, int minX
, int minY
,
549 win
->flags
.setAspect
= 1;
550 win
->minAspect
.x
= minX
;
551 win
->minAspect
.y
= minY
;
552 win
->maxAspect
.x
= maxX
;
553 win
->maxAspect
.y
= maxY
;
554 if (win
->view
->flags
.realized
)
561 WMSetWindowInitialPosition(WMWindow
*win
, int x
, int y
)
563 win
->flags
.setPPos
= 1;
566 if (win
->view
->flags
.realized
)
568 WMMoveWidget(win
, x
, y
);
574 WMSetWindowUserPosition(WMWindow
*win
, int x
, int y
)
576 win
->flags
.setUPos
= 1;
579 if (win
->view
->flags
.realized
)
581 WMMoveWidget(win
, x
, y
);
588 WMSetWindowMinSize(WMWindow
*win
, unsigned width
, unsigned height
)
590 win
->minSize
.width
= width
;
591 win
->minSize
.height
= height
;
592 if (win
->view
->flags
.realized
)
599 WMSetWindowMaxSize(WMWindow
*win
, unsigned width
, unsigned height
)
601 win
->maxSize
.width
= width
;
602 win
->maxSize
.height
= height
;
603 if (win
->view
->flags
.realized
)
609 WMSetWindowBaseSize(WMWindow
*win
, unsigned width
, unsigned height
)
611 /* TODO: validate sizes */
612 win
->baseSize
.width
= width
;
613 win
->baseSize
.height
= height
;
614 if (win
->view
->flags
.realized
)
620 WMSetWindowResizeIncrements(WMWindow
*win
, unsigned wIncr
, unsigned hIncr
)
622 win
->resizeIncrement
.width
= wIncr
;
623 win
->resizeIncrement
.height
= hIncr
;
624 if (win
->view
->flags
.realized
)
630 WMSetWindowLevel(WMWindow
*win
, int level
)
633 if (win
->view
->flags
.realized
)
634 setWindowMakerHints(win
);
639 WMSetWindowDocumentEdited(WMWindow
*win
, Bool flag
)
641 flag
= ((flag
==0) ? 0 : 1);
642 if (win
->flags
.documentEdited
!= flag
) {
643 win
->flags
.documentEdited
= flag
;
644 if (win
->view
->flags
.realized
)
645 setWindowMakerHints(win
);
651 WMSetWindowMiniwindowImage(WMWindow
*win
, RImage
*image
)
653 if (win
->view
->flags
.realized
)
654 setMiniwindow(win
, image
);
659 WMSetWindowMiniwindowPixmap(WMWindow
*win
, WMPixmap
*pixmap
)
661 if ((win
->miniImage
&& !pixmap
) || (!win
->miniImage
&& pixmap
)) {
663 WMReleasePixmap(win
->miniImage
);
666 win
->miniImage
= WMRetainPixmap(pixmap
);
668 win
->miniImage
= NULL
;
670 if (win
->view
->flags
.realized
) {
673 hints
= XGetWMHints(win
->view
->screen
->display
, win
->view
->window
);
675 hints
= XAllocWMHints();
677 wwarning("could not allocate memory for WM hints");
683 hints
->flags
|= IconPixmapHint
;
684 hints
->icon_pixmap
= WMGetPixmapXID(pixmap
);
685 hints
->icon_mask
= WMGetPixmapMaskXID(pixmap
);
686 if (hints
->icon_mask
!= None
) {
687 hints
->flags
|= IconMaskHint
;
690 XSetWMHints(win
->view
->screen
->display
, win
->view
->window
, hints
);
698 WMSetWindowMiniwindowTitle(WMWindow
*win
, char *title
)
700 if ((win
->miniTitle
&& !title
) || (!win
->miniTitle
&& title
)
701 || (title
&& win
->miniTitle
&& strcoll(title
, win
->miniTitle
)!=0)) {
703 wfree(win
->miniTitle
);
706 win
->miniTitle
= wstrdup(title
);
708 win
->miniTitle
= NULL
;
710 if (win
->view
->flags
.realized
) {
711 setMiniwindowTitle(win
, title
);
718 WMCloseWindow(WMWindow
*win
)
721 /* withdraw the window */
722 if (win
->view
->flags
.realized
)
723 XWithdrawWindow(win
->view
->screen
->display
, win
->view
->window
,
724 win
->view
->screen
->screen
);
729 handleEvents(XEvent
*event
, void *clientData
)
731 _Window
*win
= (_Window
*)clientData
;
732 W_View
*view
= win
->view
;
735 switch (event
->type
) {
737 if (event
->xclient
.message_type
== win
->view
->screen
->protocolsAtom
738 && event
->xclient
.format
== 32
739 && event
->xclient
.data
.l
[0]==win
->view
->screen
->deleteWindowAtom
) {
741 if (win
->closeAction
) {
742 (*win
->closeAction
)(win
, win
->closeData
);
747 * was causing windows to ignore commands like closeWindow
748 * after the windows is iconized/restored or a workspace change
749 * if this is really needed, put the MapNotify portion too and
750 * fix the restack bug in wmaker
764 case ConfigureNotify
:
765 if (event
->xconfigure
.width
!= view
->size
.width
766 || event
->xconfigure
.height
!= view
->size
.height
) {
768 view
->size
.width
= event
->xconfigure
.width
;
769 view
->size
.height
= event
->xconfigure
.height
;
771 if (view
->flags
.notifySizeChanged
) {
772 WMPostNotificationName(WMViewSizeDidChangeNotification
,
776 if (event
->xconfigure
.x
!= view
->pos
.x
777 || event
->xconfigure
.y
!= view
->pos
.y
) {
779 if (event
->xconfigure
.send_event
) {
780 view
->pos
.x
= event
->xconfigure
.x
;
781 view
->pos
.y
= event
->xconfigure
.y
;
785 XTranslateCoordinates(view
->screen
->display
,
786 view
->window
, view
->screen
->rootWin
,
787 event
->xconfigure
.x
, event
->xconfigure
.y
,
788 &view
->pos
.x
, &view
->pos
.y
, &foo
);
799 destroyWindow(_Window
*win
)
801 WMScreen
*scr
= win
->view
->screen
;
803 WMRemoveNotificationObserver(win
);
805 if (scr
->windowList
== win
) {
806 scr
->windowList
= scr
->windowList
->nextPtr
;
809 ptr
= scr
->windowList
;
812 while (ptr
->nextPtr
) {
813 if (ptr
->nextPtr
==win
) {
814 ptr
->nextPtr
= ptr
->nextPtr
->nextPtr
;
826 if (win
->miniTitle
) {
827 wfree(win
->miniTitle
);
830 if (win
->miniImage
) {
831 WMReleasePixmap(win
->miniImage
);