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
));
295 WMSetWindowTitle(WMWindow
*win
, char *title
)
297 if (win
->title
!=NULL
)
300 win
->title
= wstrdup(title
);
304 if (win
->view
->flags
.realized
) {
305 setWindowTitle(win
, title
);
313 WMSetWindowCloseAction(WMWindow
*win
, WMAction
*action
, void *clientData
)
318 WMScreen
*scr
= win
->view
->screen
;
320 if (win
->view
->flags
.realized
) {
321 if (action
&& !win
->closeAction
) {
322 if (!XGetWMProtocols(scr
->display
, win
->view
->window
, &atoms
,
326 newAtoms
= wmalloc((count
+1)*sizeof(Atom
));
328 memcpy(newAtoms
, atoms
, count
*sizeof(Atom
));
329 newAtoms
[count
++] = scr
->deleteWindowAtom
;
330 XSetWMProtocols(scr
->display
, win
->view
->window
, newAtoms
, count
);
334 } else if (!action
&& win
->closeAction
) {
337 if (XGetWMProtocols(scr
->display
, win
->view
->window
, &atoms
,
338 &count
) && count
>0) {
339 newAtoms
= wmalloc((count
-1)*sizeof(Atom
));
341 for (i
=0; i
< count
; i
++) {
342 if (atoms
[i
]!=scr
->deleteWindowAtom
) {
343 newAtoms
[i
] = atoms
[i
];
347 XSetWMProtocols(scr
->display
, win
->view
->window
, newAtoms
,
355 win
->closeAction
= action
;
356 win
->closeData
= clientData
;
362 willResizeWindow(W_ViewDelegate
*self
, WMView
*view
,
363 unsigned *width
, unsigned *height
)
365 WMWindow
*win
= (WMWindow
*)view
->self
;
367 if (win
->minSize
.width
> 0 && win
->minSize
.height
> 0) {
368 if (*width
< win
->minSize
.width
)
369 *width
= win
->minSize
.width
;
370 if (*height
< win
->minSize
.height
)
371 *height
= win
->minSize
.height
;
374 if (win
->maxSize
.width
> 0 && win
->maxSize
.height
> 0) {
375 if (*width
> win
->maxSize
.width
)
376 *width
= win
->maxSize
.width
;
377 if (*height
> win
->maxSize
.height
)
378 *height
= win
->maxSize
.height
;
384 setSizeHints(WMWindow
*win
)
388 hints
= XAllocSizeHints();
390 wwarning("could not allocate memory for window size hints");
396 if (win
->flags
.setPPos
) {
397 hints
->flags
|= PPosition
;
398 hints
->x
= win
->ppos
.x
;
399 hints
->y
= win
->ppos
.y
;
401 if (win
->flags
.setUPos
) {
402 hints
->flags
|= USPosition
;
403 hints
->x
= win
->upos
.x
;
404 hints
->y
= win
->upos
.y
;
406 if (win
->minSize
.width
>0 && win
->minSize
.height
>0) {
407 hints
->flags
|= PMinSize
;
408 hints
->min_width
= win
->minSize
.width
;
409 hints
->min_height
= win
->minSize
.height
;
411 if (win
->maxSize
.width
>0 && win
->maxSize
.height
>0) {
412 hints
->flags
|= PMaxSize
;
413 hints
->max_width
= win
->maxSize
.width
;
414 hints
->max_height
= win
->maxSize
.height
;
416 if (win
->baseSize
.width
>0 && win
->baseSize
.height
>0) {
417 hints
->flags
|= PBaseSize
;
418 hints
->base_width
= win
->baseSize
.width
;
419 hints
->base_height
= win
->baseSize
.height
;
421 if (win
->resizeIncrement
.width
>0 && win
->resizeIncrement
.height
>0) {
422 hints
->flags
|= PResizeInc
;
423 hints
->width_inc
= win
->resizeIncrement
.width
;
424 hints
->height_inc
= win
->resizeIncrement
.height
;
426 if (win
->flags
.setAspect
) {
427 hints
->flags
|= PAspect
;
428 hints
->min_aspect
.x
= win
->minAspect
.x
;
429 hints
->min_aspect
.y
= win
->minAspect
.y
;
430 hints
->max_aspect
.x
= win
->maxAspect
.x
;
431 hints
->max_aspect
.y
= win
->maxAspect
.y
;
436 XSetWMNormalHints(win
->view
->screen
->display
, win
->view
->window
, hints
);
444 writeGNUstepWMAttr(WMScreen
*scr
, Window window
, GNUstepWMAttributes
*attr
)
446 unsigned long data
[9];
448 /* handle idiot compilers where array of CARD32 != struct of CARD32 */
449 data
[0] = attr
->flags
;
450 data
[1] = attr
->window_style
;
451 data
[2] = attr
->window_level
;
452 data
[3] = 0; /* reserved */
453 /* The X protocol says XIDs are 32bit */
454 data
[4] = attr
->miniaturize_pixmap
;
455 data
[5] = attr
->close_pixmap
;
456 data
[6] = attr
->miniaturize_mask
;
457 data
[7] = attr
->close_mask
;
458 data
[8] = attr
->extra_flags
;
459 XChangeProperty(scr
->display
, window
, scr
->attribsAtom
, scr
->attribsAtom
,
460 32, PropModeReplace
, (unsigned char *)data
, 9);
465 setWindowMakerHints(WMWindow
*win
)
467 GNUstepWMAttributes attribs
;
468 WMScreen
*scr
= WMWidgetScreen(win
);
470 memset(&attribs
, 0, sizeof(GNUstepWMAttributes
));
471 attribs
.flags
= GSWindowStyleAttr
|GSWindowLevelAttr
|GSExtraFlagsAttr
;
472 attribs
.window_style
= win
->flags
.style
;
473 attribs
.window_level
= win
->level
;
474 if (win
->flags
.documentEdited
)
475 attribs
.extra_flags
= GSDocumentEditedFlag
;
477 attribs
.extra_flags
= 0;
479 writeGNUstepWMAttr(scr
, win
->view
->window
, &attribs
);
484 realizeWindow(WMWindow
*win
)
487 XClassHint
*classHint
;
488 WMScreen
*scr
= win
->view
->screen
;
492 classHint
= XAllocClassHint();
493 classHint
->res_name
= win
->wname
;
494 classHint
->res_class
= WMGetApplicationName();
495 XSetClassHint(scr
->display
, win
->view
->window
, classHint
);
498 hints
= XAllocWMHints();
500 if (!scr
->aflags
.simpleApplication
) {
501 hints
->flags
|= WindowGroupHint
;
502 hints
->window_group
= scr
->groupLeader
;
504 if (win
->miniImage
) {
505 hints
->flags
|= IconPixmapHint
;
506 hints
->icon_pixmap
= WMGetPixmapXID(win
->miniImage
);
507 hints
->icon_mask
= WMGetPixmapMaskXID(win
->miniImage
);
508 if (hints
->icon_mask
!= None
) {
509 hints
->flags
|= IconMaskHint
;
512 if (hints
->flags
!= 0)
513 XSetWMHints(scr
->display
, win
->view
->window
, hints
);
517 if (win
->closeAction
) {
518 atoms
[count
++] = scr
->deleteWindowAtom
;
522 XSetWMProtocols(scr
->display
, win
->view
->window
, atoms
, count
);
524 if (win
->title
|| win
->miniTitle
)
525 XmbSetWMProperties(scr
->display
, win
->view
->window
, win
->title
,
526 win
->miniTitle
, NULL
, 0, NULL
, NULL
, NULL
);
528 setWindowMakerHints(win
);
533 XSetTransientForHint(scr
->display
, win
->view
->window
,
534 win
->owner
->view
->window
);
538 setWindowTitle(win
, win
->title
);
544 WMSetWindowAspectRatio(WMWindow
*win
, int minX
, int minY
,
547 win
->flags
.setAspect
= 1;
548 win
->minAspect
.x
= minX
;
549 win
->minAspect
.y
= minY
;
550 win
->maxAspect
.x
= maxX
;
551 win
->maxAspect
.y
= maxY
;
552 if (win
->view
->flags
.realized
)
559 WMSetWindowInitialPosition(WMWindow
*win
, int x
, int y
)
561 win
->flags
.setPPos
= 1;
564 if (win
->view
->flags
.realized
)
566 WMMoveWidget(win
, x
, y
);
572 WMSetWindowUserPosition(WMWindow
*win
, int x
, int y
)
574 win
->flags
.setUPos
= 1;
577 if (win
->view
->flags
.realized
)
579 WMMoveWidget(win
, x
, y
);
586 WMSetWindowMinSize(WMWindow
*win
, unsigned width
, unsigned height
)
588 win
->minSize
.width
= width
;
589 win
->minSize
.height
= height
;
590 if (win
->view
->flags
.realized
)
597 WMSetWindowMaxSize(WMWindow
*win
, unsigned width
, unsigned height
)
599 win
->maxSize
.width
= width
;
600 win
->maxSize
.height
= height
;
601 if (win
->view
->flags
.realized
)
607 WMSetWindowBaseSize(WMWindow
*win
, unsigned width
, unsigned height
)
609 /* TODO: validate sizes */
610 win
->baseSize
.width
= width
;
611 win
->baseSize
.height
= height
;
612 if (win
->view
->flags
.realized
)
618 WMSetWindowResizeIncrements(WMWindow
*win
, unsigned wIncr
, unsigned hIncr
)
620 win
->resizeIncrement
.width
= wIncr
;
621 win
->resizeIncrement
.height
= hIncr
;
622 if (win
->view
->flags
.realized
)
628 WMSetWindowLevel(WMWindow
*win
, int level
)
631 if (win
->view
->flags
.realized
)
632 setWindowMakerHints(win
);
637 WMSetWindowDocumentEdited(WMWindow
*win
, Bool flag
)
639 flag
= ((flag
==0) ? 0 : 1);
640 if (win
->flags
.documentEdited
!= flag
) {
641 win
->flags
.documentEdited
= flag
;
642 if (win
->view
->flags
.realized
)
643 setWindowMakerHints(win
);
649 WMSetWindowMiniwindowImage(WMWindow
*win
, RImage
*image
)
651 if (win
->view
->flags
.realized
)
652 setMiniwindow(win
, image
);
657 WMSetWindowMiniwindowPixmap(WMWindow
*win
, WMPixmap
*pixmap
)
659 if ((win
->miniImage
&& !pixmap
) || (!win
->miniImage
&& pixmap
)) {
661 WMReleasePixmap(win
->miniImage
);
664 win
->miniImage
= WMRetainPixmap(pixmap
);
666 win
->miniImage
= NULL
;
668 if (win
->view
->flags
.realized
) {
671 hints
= XGetWMHints(win
->view
->screen
->display
, win
->view
->window
);
673 hints
= XAllocWMHints();
675 wwarning("could not allocate memory for WM hints");
681 hints
->flags
|= IconPixmapHint
;
682 hints
->icon_pixmap
= WMGetPixmapXID(pixmap
);
683 hints
->icon_mask
= WMGetPixmapMaskXID(pixmap
);
684 if (hints
->icon_mask
!= None
) {
685 hints
->flags
|= IconMaskHint
;
688 XSetWMHints(win
->view
->screen
->display
, win
->view
->window
, hints
);
696 WMSetWindowMiniwindowTitle(WMWindow
*win
, char *title
)
698 if ((win
->miniTitle
&& !title
) || (!win
->miniTitle
&& title
)
699 || (title
&& win
->miniTitle
&& strcoll(title
, win
->miniTitle
)!=0)) {
701 wfree(win
->miniTitle
);
704 win
->miniTitle
= wstrdup(title
);
706 win
->miniTitle
= NULL
;
708 if (win
->view
->flags
.realized
) {
709 setMiniwindowTitle(win
, title
);
716 WMCloseWindow(WMWindow
*win
)
719 /* withdraw the window */
720 if (win
->view
->flags
.realized
)
721 XWithdrawWindow(win
->view
->screen
->display
, win
->view
->window
,
722 win
->view
->screen
->screen
);
727 handleEvents(XEvent
*event
, void *clientData
)
729 _Window
*win
= (_Window
*)clientData
;
730 W_View
*view
= win
->view
;
733 switch (event
->type
) {
735 if (event
->xclient
.message_type
== win
->view
->screen
->protocolsAtom
736 && event
->xclient
.format
== 32
737 && event
->xclient
.data
.l
[0]==win
->view
->screen
->deleteWindowAtom
) {
739 if (win
->closeAction
) {
740 (*win
->closeAction
)(win
, win
->closeData
);
745 * was causing windows to ignore commands like closeWindow
746 * after the windows is iconized/restored or a workspace change
747 * if this is really needed, put the MapNotify portion too and
748 * fix the restack bug in wmaker
762 case ConfigureNotify
:
763 if (event
->xconfigure
.width
!= view
->size
.width
764 || event
->xconfigure
.height
!= view
->size
.height
) {
766 view
->size
.width
= event
->xconfigure
.width
;
767 view
->size
.height
= event
->xconfigure
.height
;
769 if (view
->flags
.notifySizeChanged
) {
770 WMPostNotificationName(WMViewSizeDidChangeNotification
,
774 if (event
->xconfigure
.x
!= view
->pos
.x
775 || event
->xconfigure
.y
!= view
->pos
.y
) {
777 if (event
->xconfigure
.send_event
) {
778 view
->pos
.x
= event
->xconfigure
.x
;
779 view
->pos
.y
= event
->xconfigure
.y
;
783 XTranslateCoordinates(view
->screen
->display
,
784 view
->window
, view
->screen
->rootWin
,
785 event
->xconfigure
.x
, event
->xconfigure
.y
,
786 &view
->pos
.x
, &view
->pos
.y
, &foo
);
797 destroyWindow(_Window
*win
)
799 WMScreen
*scr
= win
->view
->screen
;
801 WMRemoveNotificationObserver(win
);
803 if (scr
->windowList
== win
) {
804 scr
->windowList
= scr
->windowList
->nextPtr
;
807 ptr
= scr
->windowList
;
810 while (ptr
->nextPtr
) {
811 if (ptr
->nextPtr
==win
) {
812 ptr
->nextPtr
= ptr
->nextPtr
->nextPtr
;
824 if (win
->miniTitle
) {
825 wfree(win
->miniTitle
);
828 if (win
->miniImage
) {
829 WMReleasePixmap(win
->miniImage
);