2 * Window Maker window manager
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 #include <X11/Xutil.h>
32 #include "WindowMaker.h"
41 #define DBLCLICK_TIME wPreferences.dblclick_time
43 extern WPreferences wPreferences
;
45 static void handleExpose(WObjDescriptor
*desc
, XEvent
*event
);
46 static void handleButtonExpose(WObjDescriptor
*desc
, XEvent
*event
);
48 static void buttonMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
49 static void titlebarMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
50 static void resizebarMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
52 static void checkTitleSize(WFrameWindow
*fwin
);
55 static void paintButton(WCoreWindow
*button
, WTexture
*texture
,
56 unsigned long color
, WPixmap
*image
, int pushed
);
58 static void updateTitlebar(WFrameWindow
*fwin
);
62 wFrameWindowCreate(WScreen
*scr
, int wlevel
, int x
, int y
,
63 int width
, int height
, int flags
,
64 WTexture
**title_texture
, WTexture
**resize_texture
,
65 unsigned long *color
, GC
*gc
, WFont
**font
)
69 fwin
= wmalloc(sizeof(WFrameWindow
));
70 memset(fwin
, 0, sizeof(WFrameWindow
));
72 fwin
->screen_ptr
= scr
;
74 fwin
->flags
.single_texture
= (flags
& WFF_SINGLE_STATE
) ? 1 : 0;
76 fwin
->title_texture
= title_texture
;
77 fwin
->resizebar_texture
= resize_texture
;
78 fwin
->title_pixel
= color
;
82 fwin
->core
= wCoreCreateTopLevel(scr
, x
, y
, width
, height
,
84 if (wPreferences
.use_saveunders
) {
86 XSetWindowAttributes attribs
;
89 attribs
.save_under
= True
;
90 XChangeWindowAttributes(dpy
, fwin
->core
->window
, vmask
, &attribs
);
93 /* setup stacking information */
94 fwin
->core
->stacking
= wmalloc(sizeof(WStacking
));
95 fwin
->core
->stacking
->above
= NULL
;
96 fwin
->core
->stacking
->under
= NULL
;
97 fwin
->core
->stacking
->child_of
= NULL
;
98 fwin
->core
->stacking
->window_level
= wlevel
;
100 AddToStackList(fwin
->core
);
102 wFrameWindowUpdateBorders(fwin
, flags
);
110 wFrameWindowUpdateBorders(WFrameWindow
*fwin
, int flags
)
116 WScreen
*scr
= fwin
->screen_ptr
;
118 width
= fwin
->core
->width
;
119 if (flags
& WFF_IS_SHADED
)
122 height
= fwin
->core
->height
- fwin
->top_width
- fwin
->bottom_width
;
124 if (flags
& WFF_TITLEBAR
)
125 theight
= (*fwin
->font
)->height
+ TITLEBAR_EXTRA_HEIGHT
;
129 if (wPreferences
.new_style
) {
135 if (fwin
->titlebar
) {
136 /* if we had a titlebar and is requesting for one,
137 * check if the size has changed and resize it */
138 if (flags
& WFF_TITLEBAR
) {
139 fwin
->top_width
= theight
;
141 fwin
->flags
.need_texture_remake
= 1;
143 if (wPreferences
.new_style
) {
144 if (fwin
->left_button
) {
145 wCoreConfigure(fwin
->left_button
, 0, 0, bsize
, bsize
);
148 if (fwin
->right_button
) {
149 wCoreConfigure(fwin
->right_button
, width
-bsize
+1,
152 } else { /* !new_style */
153 if (fwin
->left_button
) {
154 wCoreConfigure(fwin
->left_button
, 3, (theight
-bsize
)/2,
158 if (fwin
->right_button
) {
159 wCoreConfigure(fwin
->right_button
, width
-bsize
-3,
160 (theight
-bsize
)/2, bsize
, bsize
);
163 updateTitlebar(fwin
);
165 /* we had a titlebar, but now we don't need it anymore */
166 for (i
=0; i
< (fwin
->flags
.single_texture
? 1 : 3); i
++) {
167 FREE_PIXMAP(fwin
->title_back
[i
]);
168 if (wPreferences
.new_style
) {
169 FREE_PIXMAP(fwin
->lbutton_back
[i
]);
170 FREE_PIXMAP(fwin
->rbutton_back
[i
]);
173 if (fwin
->left_button
)
174 wCoreDestroy(fwin
->left_button
);
175 fwin
->left_button
= NULL
;
177 if (fwin
->right_button
)
178 wCoreDestroy(fwin
->right_button
);
179 fwin
->right_button
= NULL
;
181 wCoreDestroy(fwin
->titlebar
);
182 fwin
->titlebar
= NULL
;
187 /* if we didn't have a titlebar and are being requested for
189 if (flags
& WFF_TITLEBAR
) {
190 fwin
->top_width
= theight
;
192 fwin
->flags
.titlebar
= 1;
193 fwin
->titlebar
= wCoreCreate(fwin
->core
, 0, 0, width
+1, theight
);
195 if (flags
& WFF_LEFT_BUTTON
) {
196 fwin
->flags
.left_button
= 1;
197 if (wPreferences
.new_style
) {
198 fwin
->left_button
= wCoreCreate(fwin
->core
, 0, 0,
200 if (width
< theight
*4) {
201 fwin
->flags
.lbutton_dont_fit
= 1;
203 XMapRaised(dpy
, fwin
->left_button
->window
);
207 wCoreCreate(fwin
->titlebar
, 3, (theight
-bsize
)/2,
210 XSetWindowBackground(dpy
, fwin
->left_button
->window
,
211 scr
->widget_texture
->normal
.pixel
);
213 if (width
< theight
*3) {
214 fwin
->flags
.lbutton_dont_fit
= 1;
216 XMapRaised(dpy
, fwin
->left_button
->window
);
222 if (flags
& WFF_RIGHT_BUTTON
) {
223 fwin
->flags
.right_button
= 1;
224 if (wPreferences
.new_style
) {
226 wCoreCreate(fwin
->core
, width
-bsize
+1, 0,
230 wCoreCreate(fwin
->titlebar
, width
-bsize
-3,
231 (theight
-bsize
)/2, bsize
, bsize
);
232 XSetWindowBackground(dpy
, fwin
->right_button
->window
,
233 scr
->widget_texture
->normal
.pixel
);
236 if (width
< theight
*2) {
237 fwin
->flags
.rbutton_dont_fit
= 1;
239 XMapRaised(dpy
, fwin
->right_button
->window
);
243 if (wPreferences
.new_style
)
244 updateTitlebar(fwin
);
246 XMapRaised(dpy
, fwin
->titlebar
->window
);
248 fwin
->flags
.need_texture_remake
= 1;
251 checkTitleSize(fwin
);
253 if (flags
& WFF_RESIZEBAR
) {
254 fwin
->bottom_width
= RESIZEBAR_HEIGHT
;
256 fwin
->bottom_width
= 0;
259 if (flags
& WFF_RESIZEBAR
) {
260 if (!fwin
->resizebar
) {
261 fwin
->flags
.resizebar
= 1;
262 fwin
->resizebar
= wCoreCreate(fwin
->core
, 0,
263 height
+ fwin
->top_width
,
264 width
, RESIZEBAR_HEIGHT
);
265 fwin
->resizebar_corner_width
= RESIZEBAR_CORNER_WIDTH
;
266 if (width
< RESIZEBAR_CORNER_WIDTH
*2 + RESIZEBAR_MIN_WIDTH
) {
267 fwin
->resizebar_corner_width
= (width
- RESIZEBAR_MIN_WIDTH
)/2;
268 if (fwin
->resizebar_corner_width
< 0)
269 fwin
->resizebar_corner_width
= 0;
272 XMapWindow(dpy
, fwin
->resizebar
->window
);
273 XLowerWindow(dpy
, fwin
->resizebar
->window
);
275 fwin
->flags
.need_texture_remake
= 1;
277 if (height
+fwin
->top_width
+fwin
->bottom_width
!= fwin
->core
->height
) {
278 wCoreConfigure(fwin
->resizebar
, 0, height
+ fwin
->top_width
,
279 width
, RESIZEBAR_HEIGHT
);
283 if (fwin
->resizebar
) {
284 fwin
->bottom_width
= 0;
285 wCoreDestroy(fwin
->resizebar
);
286 fwin
->resizebar
= NULL
;
290 if (height
+ fwin
->top_width
+ fwin
->bottom_width
!= fwin
->core
->height
291 && !(flags
& WFF_IS_SHADED
)) {
292 wFrameWindowResize(fwin
, width
,
293 height
+ fwin
->top_width
+ fwin
->bottom_width
);
296 /* setup object descriptors */
298 if (fwin
->titlebar
) {
299 fwin
->titlebar
->descriptor
.handle_expose
= handleExpose
;
300 fwin
->titlebar
->descriptor
.parent
= fwin
;
301 fwin
->titlebar
->descriptor
.parent_type
= WCLASS_FRAME
;
302 fwin
->titlebar
->descriptor
.handle_mousedown
= titlebarMouseDown
;
305 if (fwin
->resizebar
) {
306 fwin
->resizebar
->descriptor
.handle_expose
= handleExpose
;
307 fwin
->resizebar
->descriptor
.parent
= fwin
;
308 fwin
->resizebar
->descriptor
.parent_type
= WCLASS_FRAME
;
309 fwin
->resizebar
->descriptor
.handle_mousedown
= resizebarMouseDown
;
312 if (fwin
->left_button
) {
313 fwin
->left_button
->descriptor
.handle_expose
= handleButtonExpose
;
314 fwin
->left_button
->descriptor
.parent
= fwin
;
315 fwin
->left_button
->descriptor
.parent_type
= WCLASS_FRAME
;
316 fwin
->left_button
->descriptor
.handle_mousedown
= buttonMouseDown
;
319 if (fwin
->right_button
) {
320 fwin
->right_button
->descriptor
.parent
= fwin
;
321 fwin
->right_button
->descriptor
.parent_type
= WCLASS_FRAME
;
322 fwin
->right_button
->descriptor
.handle_expose
= handleButtonExpose
;
323 fwin
->right_button
->descriptor
.handle_mousedown
= buttonMouseDown
;
326 checkTitleSize(fwin
);
332 wFrameWindowDestroy(WFrameWindow
*fwin
)
336 if (fwin
->left_button
)
337 wCoreDestroy(fwin
->left_button
);
339 if (fwin
->right_button
)
340 wCoreDestroy(fwin
->right_button
);
343 wCoreDestroy(fwin
->resizebar
);
346 wCoreDestroy(fwin
->titlebar
);
348 RemoveFromStackList(fwin
->core
);
350 wCoreDestroy(fwin
->core
);
355 for (i
=0; i
< (fwin
->flags
.single_texture
? 1 : 3); i
++) {
356 FREE_PIXMAP(fwin
->title_back
[i
]);
357 if (wPreferences
.new_style
) {
358 FREE_PIXMAP(fwin
->lbutton_back
[i
]);
359 FREE_PIXMAP(fwin
->rbutton_back
[i
]);
368 wFrameWindowChangeState(WFrameWindow
*fwin
, int state
)
370 if (fwin
->flags
.state
==state
)
373 fwin
->flags
.state
= state
;
374 fwin
->flags
.need_texture_change
= 1;
376 wFrameWindowPaint(fwin
);
381 updateTitlebar(WFrameWindow
*fwin
)
386 theight
= (*fwin
->font
)->height
+ TITLEBAR_EXTRA_HEIGHT
;
389 w
= fwin
->core
->width
+ 1;
391 if (wPreferences
.new_style
) {
392 if (fwin
->flags
.hide_left_button
|| !fwin
->left_button
393 || fwin
->flags
.lbutton_dont_fit
) {
396 x
= fwin
->left_button
->width
;
397 w
-= fwin
->left_button
->width
;
401 if (wPreferences
.new_style
) {
402 if (!fwin
->flags
.hide_right_button
&& fwin
->right_button
403 && !fwin
->flags
.rbutton_dont_fit
) {
404 w
-= fwin
->right_button
->width
;
408 if (wPreferences
.new_style
|| fwin
->titlebar
->width
!=w
)
409 fwin
->flags
.need_texture_remake
= 1;
411 wCoreConfigure(fwin
->titlebar
, x
, 0, w
, theight
);
416 wFrameWindowHideButton(WFrameWindow
*fwin
, int flags
)
418 if ((flags
& WFF_RIGHT_BUTTON
) && fwin
->right_button
) {
419 XUnmapWindow(dpy
, fwin
->right_button
->window
);
420 fwin
->flags
.hide_right_button
= 1;
423 if ((flags
& WFF_LEFT_BUTTON
) && fwin
->left_button
) {
424 XUnmapWindow(dpy
, fwin
->left_button
->window
);
425 fwin
->flags
.hide_left_button
= 1;
428 if (fwin
->titlebar
) {
429 if (wPreferences
.new_style
) {
430 updateTitlebar(fwin
);
432 XClearWindow(dpy
, fwin
->titlebar
->window
);
433 wFrameWindowPaint(fwin
);
435 checkTitleSize(fwin
);
441 wFrameWindowShowButton(WFrameWindow
*fwin
, int flags
)
443 if ((flags
& WFF_RIGHT_BUTTON
) && fwin
->right_button
444 && fwin
->flags
.hide_right_button
) {
446 if (!fwin
->flags
.rbutton_dont_fit
)
447 XMapWindow(dpy
, fwin
->right_button
->window
);
449 fwin
->flags
.hide_right_button
= 0;
452 if ((flags
& WFF_LEFT_BUTTON
) && fwin
->left_button
453 && fwin
->flags
.hide_left_button
) {
455 if (!fwin
->flags
.lbutton_dont_fit
)
456 XMapWindow(dpy
, fwin
->left_button
->window
);
458 fwin
->flags
.hide_left_button
= 0;
462 if (fwin
->titlebar
) {
463 if (wPreferences
.new_style
) {
464 updateTitlebar(fwin
);
466 XClearWindow(dpy
, fwin
->titlebar
->window
);
467 wFrameWindowPaint(fwin
);
469 checkTitleSize(fwin
);
475 renderTexture(WScreen
*scr
, WTexture
*texture
, int width
, int height
,
476 int bwidth
, int bheight
, int left
, int right
,
477 Pixmap
*title
, Pixmap
*lbutton
, Pixmap
*rbutton
)
480 RImage
*limg
, *rimg
, *mimg
;
487 img
= wTextureRenderImage(texture
, width
, height
, WREL_FLAT
);
489 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode
));
493 if (wPreferences
.new_style
) {
495 limg
= RGetSubImage(img
, 0, 0, bwidth
, bheight
);
503 RBevelImage(limg
, RBEV_RAISED2
);
504 if (!RConvertImage(scr
->rcontext
, limg
, lbutton
)) {
505 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
513 rimg
= RGetSubImage(img
, width
- bwidth
, 0, bwidth
, bheight
);
518 RBevelImage(rimg
, RBEV_RAISED2
);
519 if (!RConvertImage(scr
->rcontext
, rimg
, rbutton
)) {
520 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
527 mimg
= RGetSubImage(img
, x
, 0, w
, img
->height
);
528 RBevelImage(mimg
, RBEV_RAISED2
);
530 if (!RConvertImage(scr
->rcontext
, mimg
, title
)) {
531 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
535 RBevelImage(img
, RBEV_RAISED2
);
537 if (!RConvertImage(scr
->rcontext
, img
, title
)) {
538 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
542 RBevelImage(img
, RBEV_RAISED2
);
544 if (!RConvertImage(scr
->rcontext
, img
, title
)) {
545 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
554 renderResizebarTexture(WScreen
*scr
, WTexture
*texture
, int width
, int height
,
555 int cwidth
, Pixmap
*pmap
)
563 img
= wTextureRenderImage(texture
, width
, height
, WREL_FLAT
);
565 wwarning(_("could not render texture: %s"),
566 RMessageForError(RErrorCode
));
571 light
.red
= light
.green
= light
.blue
= 80;
574 dark
.red
= dark
.green
= dark
.blue
= 40;
576 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
577 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
579 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
580 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
582 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
584 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
587 if (!RConvertImage(scr
->rcontext
, img
, pmap
)) {
588 wwarning(_("error rendering image: %s"), RMessageForError(RErrorCode
));
597 updateTexture(WFrameWindow
*fwin
)
602 i
= fwin
->flags
.state
;
603 if (fwin
->titlebar
) {
604 if (fwin
->title_texture
[i
]->any
.type
!=WTEX_SOLID
) {
605 XSetWindowBackgroundPixmap(dpy
, fwin
->titlebar
->window
,
606 fwin
->title_back
[i
]);
607 if (wPreferences
.new_style
) {
608 if (fwin
->left_button
&& fwin
->lbutton_back
[i
])
609 XSetWindowBackgroundPixmap(dpy
, fwin
->left_button
->window
,
610 fwin
->lbutton_back
[i
]);
612 if (fwin
->right_button
&& fwin
->rbutton_back
[i
])
613 XSetWindowBackgroundPixmap(dpy
, fwin
->right_button
->window
,
614 fwin
->rbutton_back
[i
]);
617 pixel
= fwin
->title_texture
[i
]->solid
.normal
.pixel
;
618 XSetWindowBackground(dpy
, fwin
->titlebar
->window
, pixel
);
619 if (wPreferences
.new_style
) {
620 if (fwin
->left_button
)
621 XSetWindowBackground(dpy
, fwin
->left_button
->window
,
623 if (fwin
->right_button
)
624 XSetWindowBackground(dpy
, fwin
->right_button
->window
,
628 XClearWindow(dpy
, fwin
->titlebar
->window
);
630 if (fwin
->left_button
) {
631 XClearWindow(dpy
, fwin
->left_button
->window
);
632 handleButtonExpose(&fwin
->left_button
->descriptor
, NULL
);
634 if (fwin
->right_button
) {
635 XClearWindow(dpy
, fwin
->right_button
->window
);
636 handleButtonExpose(&fwin
->right_button
->descriptor
, NULL
);
644 remakeTexture(WFrameWindow
*fwin
, int state
)
646 Pixmap pmap
, lpmap
, rpmap
;
648 if (fwin
->title_texture
[state
] && fwin
->titlebar
) {
649 FREE_PIXMAP(fwin
->title_back
[state
]);
650 if (wPreferences
.new_style
) {
651 FREE_PIXMAP(fwin
->lbutton_back
[state
]);
652 FREE_PIXMAP(fwin
->rbutton_back
[state
]);
655 if (fwin
->title_texture
[state
]->any
.type
!=WTEX_SOLID
) {
659 /* eventually surrounded by if new_style */
660 left
= fwin
->left_button
&& !fwin
->flags
.hide_left_button
661 && !fwin
->flags
.lbutton_dont_fit
;
662 right
= fwin
->right_button
&& !fwin
->flags
.hide_right_button
663 && !fwin
->flags
.rbutton_dont_fit
;
665 width
= fwin
->core
->width
+1;
667 renderTexture(fwin
->screen_ptr
, fwin
->title_texture
[state
],
668 width
, fwin
->titlebar
->height
,
669 fwin
->titlebar
->height
, fwin
->titlebar
->height
,
670 left
, right
, &pmap
, &lpmap
, &rpmap
);
672 fwin
->title_back
[state
] = pmap
;
673 if (wPreferences
.new_style
) {
674 fwin
->lbutton_back
[state
] = lpmap
;
675 fwin
->rbutton_back
[state
] = rpmap
;
679 if (fwin
->resizebar_texture
&& fwin
->resizebar_texture
[0]
680 && fwin
->resizebar
&& state
== 0) {
682 FREE_PIXMAP(fwin
->resizebar_back
[0]);
684 if (fwin
->resizebar_texture
[0]->any
.type
!=WTEX_SOLID
) {
686 renderResizebarTexture(fwin
->screen_ptr
,
687 fwin
->resizebar_texture
[0],
688 fwin
->resizebar
->width
,
689 fwin
->resizebar
->height
,
690 fwin
->resizebar_corner_width
,
693 fwin
->resizebar_back
[0] = pmap
;
696 /* this part should be in updateTexture() */
697 if (fwin
->resizebar_texture
[0]->any
.type
!=WTEX_SOLID
) {
698 XSetWindowBackgroundPixmap(dpy
, fwin
->resizebar
->window
,
699 fwin
->resizebar_back
[0]);
701 XSetWindowBackground(dpy
, fwin
->resizebar
->window
,
702 fwin
->resizebar_texture
[0]->solid
.normal
.pixel
);
704 XClearWindow(dpy
, fwin
->resizebar
->window
);
710 wFrameWindowPaint(WFrameWindow
*fwin
)
712 if (fwin
->flags
.is_client_window_frame
)
713 fwin
->flags
.justification
= wPreferences
.title_justification
;
715 if (fwin
->flags
.need_texture_remake
) {
718 fwin
->flags
.need_texture_remake
= 0;
719 fwin
->flags
.need_texture_change
= 0;
721 if (fwin
->flags
.single_texture
) {
722 remakeTexture(fwin
, 0);
725 /* first render the texture for the current state... */
726 remakeTexture(fwin
, fwin
->flags
.state
);
727 /* ... and paint it */
730 for (i
=0; i
< 3; i
++) {
731 if (i
!=fwin
->flags
.state
)
732 remakeTexture(fwin
, i
);
737 if (fwin
->flags
.need_texture_change
) {
738 fwin
->flags
.need_texture_change
= 0;
743 if (fwin
->titlebar
&& !fwin
->flags
.repaint_only_resizebar
744 && fwin
->title_texture
[fwin
->flags
.state
]->any
.type
==WTEX_SOLID
) {
745 wDrawBevel(fwin
->titlebar
->window
, fwin
->titlebar
->width
,
746 fwin
->titlebar
->height
,
747 (WTexSolid
*)fwin
->title_texture
[fwin
->flags
.state
],
751 if (fwin
->resizebar
&& !fwin
->flags
.repaint_only_titlebar
752 && fwin
->resizebar_texture
[0]->any
.type
== WTEX_SOLID
) {
757 WTexSolid
*texture
= (WTexSolid
*)fwin
->resizebar_texture
[0];
759 w
= fwin
->resizebar
->width
;
760 h
= fwin
->resizebar
->height
;
761 cw
= fwin
->resizebar_corner_width
;
762 light_gc
= texture
->light_gc
;
763 dim_gc
= texture
->dim_gc
;
764 win
= fwin
->resizebar
->window
;
766 XDrawLine(dpy
, win
, dim_gc
, 0, 0, w
, 0);
767 XDrawLine(dpy
, win
, light_gc
, 0, 1, w
, 1);
769 XDrawLine(dpy
, win
, dim_gc
, cw
, 2, cw
, h
);
770 XDrawLine(dpy
, win
, light_gc
, cw
+1, 2, cw
+1, h
);
772 XDrawLine(dpy
, win
, dim_gc
, w
-cw
-2, 2, w
-cw
-2, h
);
773 XDrawLine(dpy
, win
, light_gc
, w
-cw
-1, 2, w
-cw
-1, h
);
775 #ifdef SHADOW_RESIZEBAR
776 XDrawLine(dpy
, win
, light_gc
, 0, 1, 0, h
-1);
777 XDrawLine(dpy
, win
, dim_gc
, w
-1, 2, w
-1, h
-1);
778 XDrawLine(dpy
, win
, dim_gc
, 1, h
-1, cw
, h
-1);
779 XDrawLine(dpy
, win
, dim_gc
, cw
+2, h
-1, w
-cw
-2, h
-1);
780 XDrawLine(dpy
, win
, dim_gc
, w
-cw
, h
-1, w
-1, h
-1);
781 #endif /* SHADOW_RESIZEBAR */
785 if (fwin
->title
&& fwin
->titlebar
&& !fwin
->flags
.repaint_only_resizebar
) {
787 int lofs
= 6, rofs
= 6;
793 if (!wPreferences
.new_style
) {
794 if (fwin
->left_button
&& !fwin
->flags
.hide_left_button
795 && !fwin
->flags
.lbutton_dont_fit
)
796 lofs
+= fwin
->left_button
->width
+ 3;
800 if (fwin
->right_button
&& !fwin
->flags
.hide_right_button
801 && !fwin
->flags
.rbutton_dont_fit
)
802 rofs
+= fwin
->right_button
->width
+ 3;
807 #ifdef XKB_TITLE_HINT
808 if(fwin
->flags
.is_client_window_frame
) {
810 freebuff
= (char *)wmalloc((strlen(fwin
->title
)+6)*sizeof(char));
811 if (fwin
->flags
.justification
== WTJ_RIGHT
)
812 sprintf(freebuff
,"%s %s",fwin
->title
,fwin
->languagemode
?XKB_ON
:XKB_OFF
);
814 sprintf(freebuff
,"%s %s",fwin
->languagemode
?XKB_ON
:XKB_OFF
,fwin
->title
);
815 title
= ShrinkString(*fwin
->font
, freebuff
,
816 fwin
->titlebar
->width
- lofs
- rofs
);
819 else title
= ShrinkString(*fwin
->font
, fwin
->title
,
820 fwin
->titlebar
->width
- lofs
- rofs
);
822 title
= ShrinkString(*fwin
->font
, fwin
->title
,
823 fwin
->titlebar
->width
- lofs
- rofs
);
824 #endif /* XKB_TITLE_HINT */
825 titlelen
= strlen(title
);
826 w
= wTextWidth((*fwin
->font
)->font
, title
, titlelen
);
828 switch (fwin
->flags
.justification
) {
834 x
= fwin
->titlebar
->width
- w
- rofs
;
839 x
= lofs
+ (fwin
->titlebar
->width
- w
- lofs
- rofs
) / 2;
841 x
= (fwin
->titlebar
->width
- w
) / 2;
845 #ifdef TITLE_TEXT_SHADOW
846 if(wPreferences
.title_shadow
){
848 XSetForeground(dpy
, *fwin
->title_gc
,
849 fwin
->title_pixel
[fwin
->flags
.state
+3]);
850 for(shadowx
=0;shadowx
<TITLE_TEXT_SHADOW_WIDTH
;shadowx
++)
851 for(shadowy
=0;shadowy
<TITLE_TEXT_SHADOW_HEIGHT
;shadowy
++)
852 wDrawString(fwin
->titlebar
->window
, *fwin
->font
,
854 x
+ shadowx
+ TITLE_TEXT_SHADOW_X_OFFSET
,
855 (*fwin
->font
)->y
+ TITLEBAR_EXTRA_HEIGHT
/2
856 + shadowy
+ TITLE_TEXT_SHADOW_Y_OFFSET
, title
,
859 #endif /* TITLE_TEXT_SHADOW */
861 XSetForeground(dpy
, *fwin
->title_gc
,
862 fwin
->title_pixel
[fwin
->flags
.state
]);
864 wDrawString(fwin
->titlebar
->window
, *fwin
->font
,
866 (*fwin
->font
)->y
+ TITLEBAR_EXTRA_HEIGHT
/2, title
,
871 if (fwin
->left_button
)
872 handleButtonExpose(&fwin
->left_button
->descriptor
, NULL
);
873 if (fwin
->right_button
)
874 handleButtonExpose(&fwin
->right_button
->descriptor
, NULL
);
880 reconfigure(WFrameWindow
*fwin
, int x
, int y
, int width
, int height
,
883 int k
= (wPreferences
.new_style
? 4 : 3);
884 int resizedHorizontally
= 0;
887 XResizeWindow(dpy
, fwin
->core
->window
, width
, height
);
889 XMoveResizeWindow(dpy
, fwin
->core
->window
, x
, y
, width
, height
);
892 if (fwin->core->height != height && fwin->resizebar)
893 XMoveWindow(dpy, fwin->resizebar->window, 0,
894 height - fwin->resizebar->height);
896 if (fwin
->core
->width
!= width
) {
897 fwin
->flags
.need_texture_remake
= 1;
898 resizedHorizontally
= 1;
901 fwin
->core
->width
= width
;
902 fwin
->core
->height
= height
;
904 if (fwin
->titlebar
&& resizedHorizontally
) {
905 /* Check if the titlebar is wide enough to hold the buttons.
906 * Temporarily remove them if can't
908 if (fwin
->left_button
) {
909 if (width
< fwin
->top_width
*k
&& !fwin
->flags
.lbutton_dont_fit
) {
911 if (!fwin
->flags
.hide_left_button
) {
912 XUnmapWindow(dpy
, fwin
->left_button
->window
);
914 fwin
->flags
.lbutton_dont_fit
= 1;
915 } else if (width
>= fwin
->top_width
*k
&& fwin
->flags
.lbutton_dont_fit
) {
917 if (!fwin
->flags
.hide_left_button
) {
918 XMapWindow(dpy
, fwin
->left_button
->window
);
920 fwin
->flags
.lbutton_dont_fit
= 0;
924 if (fwin
->right_button
) {
925 if (width
< fwin
->top_width
*2 && !fwin
->flags
.rbutton_dont_fit
) {
927 if (!fwin
->flags
.hide_right_button
) {
928 XUnmapWindow(dpy
, fwin
->right_button
->window
);
930 fwin
->flags
.rbutton_dont_fit
= 1;
931 } else if (width
>= fwin
->top_width
*2 && fwin
->flags
.rbutton_dont_fit
) {
933 if (!fwin
->flags
.hide_right_button
) {
934 XMapWindow(dpy
, fwin
->right_button
->window
);
936 fwin
->flags
.rbutton_dont_fit
= 0;
940 if (wPreferences
.new_style
) {
941 if (fwin
->right_button
)
942 XMoveWindow(dpy
, fwin
->right_button
->window
,
943 width
- fwin
->right_button
->width
+ 1, 0);
945 if (fwin
->right_button
)
946 XMoveWindow(dpy
, fwin
->right_button
->window
,
947 width
- fwin
->right_button
->width
- 3,
948 (fwin
->titlebar
->height
- fwin
->right_button
->height
)/2);
950 updateTitlebar(fwin
);
951 checkTitleSize(fwin
);
954 if (fwin
->resizebar
) {
955 wCoreConfigure(fwin
->resizebar
, 0,
956 fwin
->core
->height
- fwin
->resizebar
->height
,
957 fwin
->core
->width
, fwin
->resizebar
->height
);
959 fwin
->resizebar_corner_width
= RESIZEBAR_CORNER_WIDTH
;
960 if (fwin
->core
->width
< RESIZEBAR_CORNER_WIDTH
*2 + RESIZEBAR_MIN_WIDTH
) {
961 fwin
->resizebar_corner_width
= fwin
->core
->width
/2;
967 wFrameWindowConfigure(WFrameWindow
*fwin
, int x
, int y
, int width
, int height
)
969 reconfigure(fwin
, x
, y
, width
, height
, False
);
973 wFrameWindowResize(WFrameWindow
*fwin
, int width
, int height
)
975 reconfigure(fwin
, 0, 0, width
, height
, True
);
981 wFrameWindowChangeTitle(WFrameWindow
*fwin
, char *new_title
)
983 /* check if the title is the same as before */
985 if (new_title
&& (strcmp(fwin
->title
, new_title
) == 0)) {
996 fwin
->title
= wstrdup(new_title
);
998 if (fwin
->titlebar
) {
999 XClearWindow(dpy
, fwin
->titlebar
->window
);
1001 wFrameWindowPaint(fwin
);
1003 checkTitleSize(fwin
);
1011 wFrameWindowUpdatePushButton(WFrameWindow
*fwin
, Bool pushed
)
1013 fwin
->flags
.right_button_pushed_in
= pushed
;
1015 paintButton(fwin
->right_button
, fwin
->title_texture
[fwin
->flags
.state
],
1016 fwin
->title_pixel
[fwin
->flags
.state
],
1017 fwin
->rbutton_image
, pushed
);
1019 #endif /* OLWM_HINTS */
1023 /*********************************************************************/
1026 handleExpose(WObjDescriptor
*desc
, XEvent
*event
)
1028 WFrameWindow
*fwin
= (WFrameWindow
*)desc
->parent
;
1031 if (fwin
->titlebar
&& fwin
->titlebar
->window
== event
->xexpose
.window
)
1032 fwin
->flags
.repaint_only_titlebar
= 1;
1033 if (fwin
->resizebar
&& fwin
->resizebar
->window
== event
->xexpose
.window
)
1034 fwin
->flags
.repaint_only_resizebar
= 1;
1035 wFrameWindowPaint(fwin
);
1036 fwin
->flags
.repaint_only_titlebar
= 0;
1037 fwin
->flags
.repaint_only_resizebar
= 0;
1042 checkTitleSize(WFrameWindow
*fwin
)
1047 fwin
->flags
.incomplete_title
= 0;
1051 if (!fwin
->titlebar
) {
1052 fwin
->flags
.incomplete_title
= 1;
1055 width
= fwin
->titlebar
->width
- 6 - 6;
1058 if (!wPreferences
.new_style
) {
1059 if (fwin
->left_button
&& !fwin
->flags
.hide_left_button
1060 && !fwin
->flags
.lbutton_dont_fit
)
1061 width
-= fwin
->left_button
->width
+ 3;
1063 if (fwin
->right_button
&& !fwin
->flags
.hide_right_button
1064 && !fwin
->flags
.rbutton_dont_fit
)
1065 width
-= fwin
->right_button
->width
+ 3;
1067 if (wTextWidth((*fwin
->font
)->font
, fwin
->title
,
1068 strlen(fwin
->title
)) > width
) {
1069 fwin
->flags
.incomplete_title
= 1;
1071 fwin
->flags
.incomplete_title
= 0;
1077 paintButton(WCoreWindow
*button
, WTexture
*texture
, unsigned long color
,
1078 WPixmap
*image
, int pushed
)
1080 WScreen
*scr
= button
->screen_ptr
;
1081 GC copy_gc
= scr
->copy_gc
;
1083 int left
=0, width
=0;
1085 /* setup stuff according to the state */
1088 if (image
->width
>=image
->height
*2) {
1089 /* the image contains 2 pictures: the second is for the
1091 width
= image
->width
/2;
1092 left
= image
->width
/2;
1094 width
= image
->width
;
1097 XSetClipMask(dpy
, copy_gc
, None
);
1098 XSetForeground(dpy
, copy_gc
, scr
->white_pixel
);
1100 if (wPreferences
.new_style
) {
1101 XFillRectangle(dpy
, button
->window
, copy_gc
, 0, 0,
1102 button
->width
-1, button
->height
-1);
1103 XSetForeground(dpy
, copy_gc
, scr
->black_pixel
);
1104 XDrawRectangle(dpy
, button
->window
, copy_gc
, 0, 0,
1105 button
->width
-1, button
->height
-1);
1107 XFillRectangle(dpy
, button
->window
, copy_gc
, 0, 0,
1108 button
->width
, button
->height
);
1109 XSetForeground(dpy
, copy_gc
, scr
->black_pixel
);
1110 XDrawRectangle(dpy
, button
->window
, copy_gc
, 0, 0,
1111 button
->width
, button
->height
);
1114 XClearWindow(dpy
, button
->window
);
1117 if (image
->width
>=image
->height
*2)
1118 width
= image
->width
/2;
1120 width
= image
->width
;
1124 if (wPreferences
.new_style
) {
1125 if (texture
->any
.type
==WTEX_SOLID
|| pushed
) {
1126 wDrawBevel(button
->window
, button
->width
, button
->height
,
1127 (WTexSolid
*)texture
, WREL_RAISED
);
1130 wDrawBevel(button
->window
, button
->width
, button
->height
,
1131 scr
->widget_texture
, WREL_RAISED
);
1137 XSetClipMask(dpy
, copy_gc
, image
->mask
);
1138 x
= (button
->width
- width
)/2 + d
;
1139 y
= (button
->height
- image
->height
)/2 + d
;
1140 XSetClipOrigin(dpy
, copy_gc
, x
-left
, y
);
1141 if (!wPreferences
.new_style
) {
1142 XSetForeground(dpy
, copy_gc
, scr
->black_pixel
);
1144 if (image
->depth
==1)
1145 XCopyPlane(dpy
, image
->image
, button
->window
, copy_gc
,
1146 left
, 0, width
, image
->height
, x
, y
, 1);
1148 XCopyArea(dpy
, image
->image
, button
->window
, copy_gc
,
1149 left
, 0, width
, image
->height
, x
, y
);
1151 XSetForeground(dpy
, copy_gc
, scr
->dark_pixel
);
1152 XFillRectangle(dpy
, button
->window
, copy_gc
, 0, 0,
1153 button
->width
, button
->height
);
1157 XSetForeground(dpy
, copy_gc
, scr
->black_pixel
);
1159 XSetForeground(dpy
, copy_gc
, color
);
1160 XSetBackground(dpy
, copy_gc
, texture
->any
.color
.pixel
);
1162 XFillRectangle(dpy
, button
->window
, copy_gc
, 0, 0,
1163 button
->width
, button
->height
);
1170 handleButtonExpose(WObjDescriptor
*desc
, XEvent
*event
)
1172 WFrameWindow
*fwin
= (WFrameWindow
*)desc
->parent
;
1173 WCoreWindow
*button
= (WCoreWindow
*)desc
->self
;
1175 if (button
== fwin
->left_button
) {
1176 paintButton(button
, fwin
->title_texture
[fwin
->flags
.state
],
1177 fwin
->title_pixel
[fwin
->flags
.state
],
1178 fwin
->lbutton_image
, False
);
1180 Bool pushed
= False
;
1183 if (fwin
->flags
.right_button_pushed_in
)
1186 /* emulate the olwm pushpin in the "out" state */
1187 paintButton(button
, fwin
->title_texture
[fwin
->flags
.state
],
1188 fwin
->title_pixel
[fwin
->flags
.state
],
1189 fwin
->rbutton_image
, pushed
);
1195 titlebarMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1197 WFrameWindow
*fwin
= desc
->parent
;
1198 WCoreWindow
*titlebar
= desc
->self
;
1200 if (IsDoubleClick(fwin
->core
->screen_ptr
, event
)) {
1201 if (fwin
->on_dblclick_titlebar
)
1202 (*fwin
->on_dblclick_titlebar
)(titlebar
, fwin
->child
, event
);
1204 if (fwin
->on_mousedown_titlebar
)
1205 (*fwin
->on_mousedown_titlebar
)(titlebar
, fwin
->child
, event
);
1211 resizebarMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1213 WFrameWindow
*fwin
= desc
->parent
;
1214 WCoreWindow
*resizebar
= desc
->self
;
1216 if (fwin
->on_mousedown_resizebar
)
1217 (*fwin
->on_mousedown_resizebar
)(resizebar
, fwin
->child
, event
);
1222 buttonMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1224 WFrameWindow
*fwin
= desc
->parent
;
1225 WCoreWindow
*button
= desc
->self
;
1228 int done
=0, execute
=1;
1230 unsigned long pixel
;
1231 int clickButton
= event
->xbutton
.button
;
1233 if (IsDoubleClick(fwin
->core
->screen_ptr
, event
)) {
1234 if (button
== fwin
->right_button
&& fwin
->on_dblclick_right
) {
1235 (*fwin
->on_dblclick_right
)(button
, fwin
->child
, event
);
1240 if (button
== fwin
->left_button
) {
1241 image
= fwin
->lbutton_image
;
1243 image
= fwin
->rbutton_image
;
1246 pixel
= fwin
->title_pixel
[fwin
->flags
.state
];
1247 texture
= fwin
->title_texture
[fwin
->flags
.state
];
1248 paintButton(button
, texture
, pixel
, image
, True
);
1251 WMMaskEvent(dpy
, LeaveWindowMask
|EnterWindowMask
|ButtonReleaseMask
1252 |ButtonPressMask
|ExposureMask
, &ev
);
1256 paintButton(button
, texture
, pixel
, image
, False
);
1261 paintButton(button
, texture
, pixel
, image
, True
);
1268 if (ev
.xbutton
.button
== clickButton
)
1276 paintButton(button
, texture
, pixel
, image
, False
);
1279 if (button
== fwin
->left_button
) {
1280 if (fwin
->on_click_left
)
1281 (*fwin
->on_click_left
)(button
, fwin
->child
, &ev
);
1282 } else if (button
== fwin
->right_button
) {
1283 if (fwin
->on_click_right
)
1284 (*fwin
->on_click_right
)(button
, fwin
->child
, &ev
);