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
);
203 WMSetWindowTitle(WMWindow
*win
, char *title
)
205 XTextProperty property
;
208 if (win
->title
!=NULL
)
211 win
->title
= wstrdup(title
);
215 if (win
->view
->flags
.realized
) {
216 result
= XmbTextListToTextProperty (win
->view
->screen
->display
,
217 &title
, 1, XStdICCTextStyle
,
219 if (result
== XNoMemory
|| result
== XLocaleNotSupported
) {
220 wwarning("window title conversion error... using STRING encoding");
221 XStoreName(win
->view
->screen
->display
, win
->view
->window
, title
);
223 XSetWMName(win
->view
->screen
->display
, win
->view
->window
, &property
);
225 XFree(property
.value
);
234 WMSetWindowCloseAction(WMWindow
*win
, WMAction
*action
, void *clientData
)
239 WMScreen
*scr
= win
->view
->screen
;
241 if (win
->view
->flags
.realized
) {
242 if (action
&& !win
->closeAction
) {
243 if (!XGetWMProtocols(scr
->display
, win
->view
->window
, &atoms
,
247 newAtoms
= wmalloc((count
+1)*sizeof(Atom
));
249 memcpy(newAtoms
, atoms
, count
*sizeof(Atom
));
250 newAtoms
[count
++] = scr
->deleteWindowAtom
;
251 XSetWMProtocols(scr
->display
, win
->view
->window
, newAtoms
, count
);
255 } else if (!action
&& win
->closeAction
) {
258 if (XGetWMProtocols(scr
->display
, win
->view
->window
, &atoms
,
259 &count
) && count
>0) {
260 newAtoms
= wmalloc((count
-1)*sizeof(Atom
));
262 for (i
=0; i
< count
; i
++) {
263 if (atoms
[i
]!=scr
->deleteWindowAtom
) {
264 newAtoms
[i
] = atoms
[i
];
268 XSetWMProtocols(scr
->display
, win
->view
->window
, newAtoms
,
276 win
->closeAction
= action
;
277 win
->closeData
= clientData
;
283 willResizeWindow(W_ViewDelegate
*self
, WMView
*view
,
284 unsigned *width
, unsigned *height
)
286 WMWindow
*win
= (WMWindow
*)view
->self
;
288 if (win
->minSize
.width
> 0 && win
->minSize
.height
> 0) {
289 if (*width
< win
->minSize
.width
)
290 *width
= win
->minSize
.width
;
291 if (*height
< win
->minSize
.height
)
292 *height
= win
->minSize
.height
;
295 if (win
->maxSize
.width
> 0 && win
->maxSize
.height
> 0) {
296 if (*width
> win
->maxSize
.width
)
297 *width
= win
->maxSize
.width
;
298 if (*height
> win
->maxSize
.height
)
299 *height
= win
->maxSize
.height
;
305 setSizeHints(WMWindow
*win
)
309 hints
= XAllocSizeHints();
311 wwarning("could not allocate memory for window size hints");
317 if (win
->flags
.setPPos
) {
318 hints
->flags
|= PPosition
;
319 hints
->x
= win
->ppos
.x
;
320 hints
->y
= win
->ppos
.y
;
322 if (win
->flags
.setUPos
) {
323 hints
->flags
|= USPosition
;
324 hints
->x
= win
->upos
.x
;
325 hints
->y
= win
->upos
.y
;
327 if (win
->minSize
.width
>0 && win
->minSize
.height
>0) {
328 hints
->flags
|= PMinSize
;
329 hints
->min_width
= win
->minSize
.width
;
330 hints
->min_height
= win
->minSize
.height
;
332 if (win
->maxSize
.width
>0 && win
->maxSize
.height
>0) {
333 hints
->flags
|= PMaxSize
;
334 hints
->max_width
= win
->maxSize
.width
;
335 hints
->max_height
= win
->maxSize
.height
;
337 if (win
->baseSize
.width
>0 && win
->baseSize
.height
>0) {
338 hints
->flags
|= PBaseSize
;
339 hints
->base_width
= win
->baseSize
.width
;
340 hints
->base_height
= win
->baseSize
.height
;
342 if (win
->resizeIncrement
.width
>0 && win
->resizeIncrement
.height
>0) {
343 hints
->flags
|= PResizeInc
;
344 hints
->width_inc
= win
->resizeIncrement
.width
;
345 hints
->height_inc
= win
->resizeIncrement
.height
;
347 if (win
->flags
.setAspect
) {
348 hints
->flags
|= PAspect
;
349 hints
->min_aspect
.x
= win
->minAspect
.x
;
350 hints
->min_aspect
.y
= win
->minAspect
.y
;
351 hints
->max_aspect
.x
= win
->maxAspect
.x
;
352 hints
->max_aspect
.y
= win
->maxAspect
.y
;
357 XSetWMNormalHints(win
->view
->screen
->display
, win
->view
->window
, hints
);
365 writeGNUstepWMAttr(WMScreen
*scr
, Window window
, GNUstepWMAttributes
*attr
)
367 unsigned long data
[9];
369 /* handle idiot compilers where array of CARD32 != struct of CARD32 */
370 data
[0] = attr
->flags
;
371 data
[1] = attr
->window_style
;
372 data
[2] = attr
->window_level
;
373 data
[3] = 0; /* reserved */
374 /* The X protocol says XIDs are 32bit */
375 data
[4] = attr
->miniaturize_pixmap
;
376 data
[5] = attr
->close_pixmap
;
377 data
[6] = attr
->miniaturize_mask
;
378 data
[7] = attr
->close_mask
;
379 data
[8] = attr
->extra_flags
;
380 XChangeProperty(scr
->display
, window
, scr
->attribsAtom
, scr
->attribsAtom
,
381 32, PropModeReplace
, (unsigned char *)data
, 9);
386 setWindowMakerHints(WMWindow
*win
)
388 GNUstepWMAttributes attribs
;
389 WMScreen
*scr
= WMWidgetScreen(win
);
391 memset(&attribs
, 0, sizeof(GNUstepWMAttributes
));
392 attribs
.flags
= GSWindowStyleAttr
|GSWindowLevelAttr
|GSExtraFlagsAttr
;
393 attribs
.window_style
= win
->flags
.style
;
394 attribs
.window_level
= win
->level
;
395 if (win
->flags
.documentEdited
)
396 attribs
.extra_flags
= GSDocumentEditedFlag
;
398 attribs
.extra_flags
= 0;
400 writeGNUstepWMAttr(scr
, win
->view
->window
, &attribs
);
405 realizeWindow(WMWindow
*win
)
408 XClassHint
*classHint
;
409 WMScreen
*scr
= win
->view
->screen
;
413 classHint
= XAllocClassHint();
414 classHint
->res_name
= win
->wname
;
415 classHint
->res_class
= WMGetApplicationName();
416 XSetClassHint(scr
->display
, win
->view
->window
, classHint
);
419 hints
= XAllocWMHints();
421 if (!scr
->aflags
.simpleApplication
) {
422 hints
->flags
|= WindowGroupHint
;
423 hints
->window_group
= scr
->groupLeader
;
425 if (win
->miniImage
) {
426 hints
->flags
|= IconPixmapHint
;
427 hints
->icon_pixmap
= WMGetPixmapXID(win
->miniImage
);
428 hints
->icon_mask
= WMGetPixmapMaskXID(win
->miniImage
);
429 if (hints
->icon_mask
!= None
) {
430 hints
->flags
|= IconMaskHint
;
433 if (hints
->flags
!= 0)
434 XSetWMHints(scr
->display
, win
->view
->window
, hints
);
438 if (win
->closeAction
) {
439 atoms
[count
++] = scr
->deleteWindowAtom
;
443 XSetWMProtocols(scr
->display
, win
->view
->window
, atoms
, count
);
445 if (win
->title
|| win
->miniTitle
)
446 XmbSetWMProperties(scr
->display
, win
->view
->window
, win
->title
,
447 win
->miniTitle
, NULL
, 0, NULL
, NULL
, NULL
);
449 setWindowMakerHints(win
);
454 XSetTransientForHint(scr
->display
, win
->view
->window
,
455 win
->owner
->view
->window
);
462 WMSetWindowAspectRatio(WMWindow
*win
, int minX
, int minY
,
465 win
->flags
.setAspect
= 1;
466 win
->minAspect
.x
= minX
;
467 win
->minAspect
.y
= minY
;
468 win
->maxAspect
.x
= maxX
;
469 win
->maxAspect
.y
= maxY
;
470 if (win
->view
->flags
.realized
)
477 WMSetWindowInitialPosition(WMWindow
*win
, int x
, int y
)
479 win
->flags
.setPPos
= 1;
482 if (win
->view
->flags
.realized
)
484 WMMoveWidget(win
, x
, y
);
490 WMSetWindowUserPosition(WMWindow
*win
, int x
, int y
)
492 win
->flags
.setUPos
= 1;
495 if (win
->view
->flags
.realized
)
497 WMMoveWidget(win
, x
, y
);
504 WMSetWindowMinSize(WMWindow
*win
, unsigned width
, unsigned height
)
506 win
->minSize
.width
= width
;
507 win
->minSize
.height
= height
;
508 if (win
->view
->flags
.realized
)
515 WMSetWindowMaxSize(WMWindow
*win
, unsigned width
, unsigned height
)
517 win
->maxSize
.width
= width
;
518 win
->maxSize
.height
= height
;
519 if (win
->view
->flags
.realized
)
525 WMSetWindowBaseSize(WMWindow
*win
, unsigned width
, unsigned height
)
527 /* TODO: validate sizes */
528 win
->baseSize
.width
= width
;
529 win
->baseSize
.height
= height
;
530 if (win
->view
->flags
.realized
)
536 WMSetWindowResizeIncrements(WMWindow
*win
, unsigned wIncr
, unsigned hIncr
)
538 win
->resizeIncrement
.width
= wIncr
;
539 win
->resizeIncrement
.height
= hIncr
;
540 if (win
->view
->flags
.realized
)
546 WMSetWindowLevel(WMWindow
*win
, int level
)
549 if (win
->view
->flags
.realized
)
550 setWindowMakerHints(win
);
555 WMSetWindowDocumentEdited(WMWindow
*win
, Bool flag
)
557 if (win
->flags
.documentEdited
!= flag
) {
558 win
->flags
.documentEdited
= flag
;
559 if (win
->view
->flags
.realized
)
560 setWindowMakerHints(win
);
566 WMSetWindowMiniwindowPixmap(WMWindow
*win
, WMPixmap
*pixmap
)
568 if ((win
->miniImage
&& !pixmap
) || (!win
->miniImage
&& pixmap
)) {
570 WMReleasePixmap(win
->miniImage
);
573 win
->miniImage
= WMRetainPixmap(pixmap
);
575 win
->miniImage
= NULL
;
577 if (win
->view
->flags
.realized
) {
580 hints
= XGetWMHints(win
->view
->screen
->display
, win
->view
->window
);
582 hints
= XAllocWMHints();
584 wwarning("could not allocate memory for WM hints");
590 hints
->flags
|= IconPixmapHint
;
591 hints
->icon_pixmap
= WMGetPixmapXID(pixmap
);
592 hints
->icon_mask
= WMGetPixmapMaskXID(pixmap
);
593 if (hints
->icon_mask
!= None
) {
594 hints
->flags
|= IconMaskHint
;
597 XSetWMHints(win
->view
->screen
->display
, win
->view
->window
, hints
);
605 WMSetWindowMiniwindowTitle(WMWindow
*win
, char *title
)
607 XTextProperty property
;
610 if ((win
->miniTitle
&& !title
) || (!win
->miniTitle
&& title
)
611 || (title
&& win
->miniTitle
&& strcoll(title
, win
->miniTitle
)!=0)) {
613 wfree(win
->miniTitle
);
616 win
->miniTitle
= wstrdup(title
);
618 win
->miniTitle
= NULL
;
620 if (win
->view
->flags
.realized
) {
621 result
= XmbTextListToTextProperty (win
->view
->screen
->display
,
622 &title
, 1, XStdICCTextStyle
,
624 if (result
== XNoMemory
|| result
== XLocaleNotSupported
) {
625 wwarning("icon title conversion error..using STRING encoding");
626 XSetIconName(win
->view
->screen
->display
, win
->view
->window
,
629 XSetWMIconName(win
->view
->screen
->display
, win
->view
->window
,
632 XFree(property
.value
);
640 WMCloseWindow(WMWindow
*win
)
643 /* withdraw the window */
644 if (win
->view
->flags
.realized
)
645 XWithdrawWindow(win
->view
->screen
->display
, win
->view
->window
,
646 win
->view
->screen
->screen
);
651 handleEvents(XEvent
*event
, void *clientData
)
653 _Window
*win
= (_Window
*)clientData
;
654 W_View
*view
= win
->view
;
657 switch (event
->type
) {
659 if (event
->xclient
.message_type
== win
->view
->screen
->protocolsAtom
660 && event
->xclient
.format
== 32
661 && event
->xclient
.data
.l
[0]==win
->view
->screen
->deleteWindowAtom
) {
663 if (win
->closeAction
) {
664 (*win
->closeAction
)(win
, win
->closeData
);
669 // was causing windows to ignore commands like closeWindow
670 * // after the windows is iconized/restored or a workspace change
671 * // if this is really needed, put the MapNotify portion too and
672 * // fix the restack bug in wmaker
686 case ConfigureNotify
:
687 if (event
->xconfigure
.width
!= view
->size
.width
688 || event
->xconfigure
.height
!= view
->size
.height
) {
690 view
->size
.width
= event
->xconfigure
.width
;
691 view
->size
.height
= event
->xconfigure
.height
;
693 if (view
->flags
.notifySizeChanged
) {
694 WMPostNotificationName(WMViewSizeDidChangeNotification
,
698 if (event
->xconfigure
.x
!= view
->pos
.x
699 || event
->xconfigure
.y
!= view
->pos
.y
) {
701 if (event
->xconfigure
.send_event
) {
702 view
->pos
.x
= event
->xconfigure
.x
;
703 view
->pos
.y
= event
->xconfigure
.y
;
707 XTranslateCoordinates(view
->screen
->display
,
708 view
->window
, view
->screen
->rootWin
,
709 event
->xconfigure
.x
, event
->xconfigure
.y
,
710 &view
->pos
.x
, &view
->pos
.y
, &foo
);
721 destroyWindow(_Window
*win
)
723 WMScreen
*scr
= win
->view
->screen
;
725 WMRemoveNotificationObserver(win
);
727 if (scr
->windowList
== win
) {
728 scr
->windowList
= scr
->windowList
->nextPtr
;
731 ptr
= scr
->windowList
;
734 while (ptr
->nextPtr
) {
735 if (ptr
->nextPtr
==win
) {
736 ptr
->nextPtr
= ptr
->nextPtr
->nextPtr
;
748 if (win
->miniTitle
) {
749 wfree(win
->miniTitle
);
752 if (win
->miniImage
) {
753 WMReleasePixmap(win
->miniImage
);