fix compilation probs
[wmaker-crm.git] / src / framewin.c
blob1938d88fbe16104c51f8d607efb919eabd4c2e35
1 /*
2 * Window Maker window manager
3 *
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
5 *
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,
19 * USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #ifdef KEEP_XKB_LOCK_STATUS
27 #include <X11/XKBlib.h>
28 #endif /* KEEP_XKB_LOCK_STATUS */
30 #include <stdlib.h>
31 #include <string.h>
33 #include <wraster.h>
35 #include "WindowMaker.h"
36 #include "GNUstep.h"
37 #include "texture.h"
38 #include "screen.h"
39 #include "wcore.h"
40 #include "framewin.h"
41 #include "stacking.h"
42 #include "funcs.h"
44 #define DBLCLICK_TIME wPreferences.dblclick_time
46 extern WPreferences wPreferences;
48 static void handleExpose(WObjDescriptor *desc, XEvent *event);
49 static void handleButtonExpose(WObjDescriptor *desc, XEvent *event);
51 static void buttonMouseDown(WObjDescriptor *desc, XEvent *event);
52 static void titlebarMouseDown(WObjDescriptor *desc, XEvent *event);
53 static void resizebarMouseDown(WObjDescriptor *desc, XEvent *event);
55 static void checkTitleSize(WFrameWindow *fwin);
58 static void paintButton(WCoreWindow *button, WTexture *texture,
59 unsigned long color, WPixmap *image, int pushed);
61 static void updateTitlebar(WFrameWindow *fwin);
64 WFrameWindow*
65 wFrameWindowCreate(WScreen *scr, int wlevel, int x, int y,
66 int width, int height, int flags,
67 WTexture **title_texture, WTexture **resize_texture,
68 unsigned long *color, GC *gc, WMFont **font)
70 WFrameWindow *fwin;
72 fwin = wmalloc(sizeof(WFrameWindow));
73 memset(fwin, 0, sizeof(WFrameWindow));
75 fwin->screen_ptr = scr;
77 fwin->flags.single_texture = (flags & WFF_SINGLE_STATE) ? 1 : 0;
79 fwin->title_texture = title_texture;
80 fwin->resizebar_texture = resize_texture;
81 fwin->title_pixel = color;
82 fwin->title_gc = gc;
83 fwin->font = font;
84 #ifdef KEEP_XKB_LOCK_STATUS
85 fwin->languagemode = XkbGroup1Index;
86 fwin->last_languagemode = XkbGroup2Index;
87 #endif
89 fwin->core = wCoreCreateTopLevel(scr, x, y, width, height,
90 FRAME_BORDER_WIDTH);
91 if (wPreferences.use_saveunders) {
92 unsigned long vmask;
93 XSetWindowAttributes attribs;
95 vmask = CWSaveUnder;
96 attribs.save_under = True;
97 XChangeWindowAttributes(dpy, fwin->core->window, vmask, &attribs);
100 /* setup stacking information */
101 fwin->core->stacking = wmalloc(sizeof(WStacking));
102 fwin->core->stacking->above = NULL;
103 fwin->core->stacking->under = NULL;
104 fwin->core->stacking->child_of = NULL;
105 fwin->core->stacking->window_level = wlevel;
107 AddToStackList(fwin->core);
109 wFrameWindowUpdateBorders(fwin, flags);
111 return fwin;
116 void
117 wFrameWindowUpdateBorders(WFrameWindow *fwin, int flags)
119 int theight;
120 int bsize;
121 int width, height;
122 int i;
123 WScreen *scr = fwin->screen_ptr;
125 width = fwin->core->width;
126 if (flags & WFF_IS_SHADED)
127 height = -1;
128 else
129 height = fwin->core->height - fwin->top_width - fwin->bottom_width;
131 if (flags & WFF_TITLEBAR)
132 theight = WMFontHeight(*fwin->font) + TITLEBAR_EXTRA_HEIGHT;
133 else
134 theight = 0;
136 if (wPreferences.new_style) {
137 bsize = theight;
138 } else {
139 bsize = theight - 7;
142 if (fwin->titlebar) {
143 /* if we had a titlebar and is requesting for one,
144 * check if the size has changed and resize it */
145 if (flags & WFF_TITLEBAR) {
146 fwin->top_width = theight;
148 fwin->flags.need_texture_remake = 1;
150 if (wPreferences.new_style) {
151 if (fwin->left_button) {
152 wCoreConfigure(fwin->left_button, 0, 0, bsize, bsize);
154 #ifdef XKB_BUTTON_HINT
155 if (fwin->language_button)
156 if (fwin->flags.hide_left_button || !fwin->left_button
157 || fwin->flags.lbutton_dont_fit) {
158 wCoreConfigure(fwin->language_button, 0, 0, bsize, bsize);
159 } else {
160 wCoreConfigure(fwin->language_button, bsize, 0, bsize, bsize);
162 #endif
165 if (fwin->right_button) {
166 wCoreConfigure(fwin->right_button, width-bsize+1,
167 0, bsize, bsize);
169 } else { /* !new_style */
170 if (fwin->left_button) {
171 wCoreConfigure(fwin->left_button, 3, (theight-bsize)/2,
172 bsize, bsize);
175 #ifdef XKB_BUTTON_HINT
176 if (fwin->language_button) {
177 wCoreConfigure(fwin->language_button, 6 + bsize, (theight-bsize)/2,
178 bsize, bsize);
181 #endif
183 if (fwin->right_button) {
184 wCoreConfigure(fwin->right_button, width-bsize-3,
185 (theight-bsize)/2, bsize, bsize);
188 updateTitlebar(fwin);
189 } else {
190 /* we had a titlebar, but now we don't need it anymore */
191 for (i=0; i < (fwin->flags.single_texture ? 1 : 3); i++) {
192 FREE_PIXMAP(fwin->title_back[i]);
193 if (wPreferences.new_style) {
194 FREE_PIXMAP(fwin->lbutton_back[i]);
195 FREE_PIXMAP(fwin->rbutton_back[i]);
196 #ifdef XKB_BUTTON_HINT
197 FREE_PIXMAP(fwin->languagebutton_back[i]);
198 #endif
201 if (fwin->left_button)
202 wCoreDestroy(fwin->left_button);
203 fwin->left_button = NULL;
205 #ifdef XKB_BUTTON_HINT
206 if (fwin->language_button)
207 wCoreDestroy(fwin->language_button);
208 fwin->language_button = NULL;
209 #endif
211 if (fwin->right_button)
212 wCoreDestroy(fwin->right_button);
213 fwin->right_button = NULL;
215 wCoreDestroy(fwin->titlebar);
216 fwin->titlebar = NULL;
218 fwin->top_width = 0;
220 } else {
221 /* if we didn't have a titlebar and are being requested for
222 * one, create it */
223 if (flags & WFF_TITLEBAR) {
224 fwin->top_width = theight;
226 fwin->flags.titlebar = 1;
227 fwin->titlebar = wCoreCreate(fwin->core, 0, 0, width+1, theight);
229 if (flags & WFF_LEFT_BUTTON) {
230 fwin->flags.left_button = 1;
231 if (wPreferences.new_style) {
232 fwin->left_button = wCoreCreate(fwin->core, 0, 0,
233 bsize, bsize);
234 if (width < theight*4) {
235 fwin->flags.lbutton_dont_fit = 1;
236 } else {
237 XMapRaised(dpy, fwin->left_button->window);
239 } else {
240 fwin->left_button =
241 wCoreCreate(fwin->titlebar, 3, (theight-bsize)/2,
242 bsize, bsize);
244 XSetWindowBackground(dpy, fwin->left_button->window,
245 scr->widget_texture->normal.pixel);
247 if (width < theight*3) {
248 fwin->flags.lbutton_dont_fit = 1;
249 } else {
250 XMapRaised(dpy, fwin->left_button->window);
255 #ifdef XKB_BUTTON_HINT
256 if (flags & WFF_LANGUAGE_BUTTON) {
257 fwin->flags.language_button = 1;
258 if (wPreferences.new_style) {
259 fwin->language_button = wCoreCreate(fwin->core,
260 bsize, 0, bsize, bsize);
262 if (width < theight*4) {
263 fwin->flags.languagebutton_dont_fit = 1;
264 } else {
265 XMapRaised(dpy, fwin->language_button->window);
267 } else {
268 fwin->language_button =
269 wCoreCreate(fwin->titlebar, bsize + 6, (theight-bsize)/2,
270 bsize, bsize);
272 XSetWindowBackground(dpy, fwin->language_button->window,
273 scr->widget_texture->normal.pixel);
275 if (width < theight*3) {
276 fwin->flags.languagebutton_dont_fit = 1;
277 } else {
278 XMapRaised(dpy, fwin->language_button->window);
282 #endif
284 if (flags & WFF_RIGHT_BUTTON) {
285 fwin->flags.right_button = 1;
286 if (wPreferences.new_style) {
287 fwin->right_button =
288 wCoreCreate(fwin->core, width-bsize+1, 0,
289 bsize, bsize);
290 } else {
291 fwin->right_button =
292 wCoreCreate(fwin->titlebar, width-bsize-3,
293 (theight-bsize)/2, bsize, bsize);
294 XSetWindowBackground(dpy, fwin->right_button->window,
295 scr->widget_texture->normal.pixel);
298 if (width < theight*2) {
299 fwin->flags.rbutton_dont_fit = 1;
300 } else {
301 XMapRaised(dpy, fwin->right_button->window);
305 if (wPreferences.new_style)
306 updateTitlebar(fwin);
308 XMapRaised(dpy, fwin->titlebar->window);
310 fwin->flags.need_texture_remake = 1;
313 checkTitleSize(fwin);
315 if (flags & WFF_RESIZEBAR) {
316 fwin->bottom_width = RESIZEBAR_HEIGHT;
317 } else {
318 fwin->bottom_width = 0;
321 if (flags & WFF_RESIZEBAR) {
322 if (!fwin->resizebar) {
323 fwin->flags.resizebar = 1;
324 fwin->resizebar = wCoreCreate(fwin->core, 0,
325 height + fwin->top_width,
326 width, RESIZEBAR_HEIGHT);
327 fwin->resizebar_corner_width = RESIZEBAR_CORNER_WIDTH;
328 if (width < RESIZEBAR_CORNER_WIDTH*2 + RESIZEBAR_MIN_WIDTH) {
329 fwin->resizebar_corner_width = (width - RESIZEBAR_MIN_WIDTH)/2;
330 if (fwin->resizebar_corner_width < 0)
331 fwin->resizebar_corner_width = 0;
334 XMapWindow(dpy, fwin->resizebar->window);
335 XLowerWindow(dpy, fwin->resizebar->window);
337 fwin->flags.need_texture_remake = 1;
338 } else {
339 if (height+fwin->top_width+fwin->bottom_width != fwin->core->height) {
340 wCoreConfigure(fwin->resizebar, 0, height + fwin->top_width,
341 width, RESIZEBAR_HEIGHT);
344 } else {
345 if (fwin->resizebar) {
346 fwin->bottom_width = 0;
347 wCoreDestroy(fwin->resizebar);
348 fwin->resizebar = NULL;
352 if (height + fwin->top_width + fwin->bottom_width != fwin->core->height
353 && !(flags & WFF_IS_SHADED)) {
354 wFrameWindowResize(fwin, width,
355 height + fwin->top_width + fwin->bottom_width);
358 /* setup object descriptors */
360 if (fwin->titlebar) {
361 fwin->titlebar->descriptor.handle_expose = handleExpose;
362 fwin->titlebar->descriptor.parent = fwin;
363 fwin->titlebar->descriptor.parent_type = WCLASS_FRAME;
364 fwin->titlebar->descriptor.handle_mousedown = titlebarMouseDown;
367 if (fwin->resizebar) {
368 fwin->resizebar->descriptor.handle_expose = handleExpose;
369 fwin->resizebar->descriptor.parent = fwin;
370 fwin->resizebar->descriptor.parent_type = WCLASS_FRAME;
371 fwin->resizebar->descriptor.handle_mousedown = resizebarMouseDown;
374 if (fwin->left_button) {
375 fwin->left_button->descriptor.handle_expose = handleButtonExpose;
376 fwin->left_button->descriptor.parent = fwin;
377 fwin->left_button->descriptor.parent_type = WCLASS_FRAME;
378 fwin->left_button->descriptor.handle_mousedown = buttonMouseDown;
381 #ifdef XKB_BUTTON_HINT
382 if (fwin->language_button) {
383 fwin->language_button->descriptor.handle_expose = handleButtonExpose;
384 fwin->language_button->descriptor.parent = fwin;
385 fwin->language_button->descriptor.parent_type = WCLASS_FRAME;
386 fwin->language_button->descriptor.handle_mousedown = buttonMouseDown;
388 #endif
391 if (fwin->right_button) {
392 fwin->right_button->descriptor.parent = fwin;
393 fwin->right_button->descriptor.parent_type = WCLASS_FRAME;
394 fwin->right_button->descriptor.handle_expose = handleButtonExpose;
395 fwin->right_button->descriptor.handle_mousedown = buttonMouseDown;
398 checkTitleSize(fwin);
403 void
404 wFrameWindowDestroy(WFrameWindow *fwin)
406 int i;
408 if (fwin->left_button)
409 wCoreDestroy(fwin->left_button);
411 #ifdef XKB_BUTTON_HINT
412 if (fwin->language_button)
413 wCoreDestroy(fwin->language_button);
414 #endif
416 if (fwin->right_button)
417 wCoreDestroy(fwin->right_button);
419 if (fwin->resizebar)
420 wCoreDestroy(fwin->resizebar);
422 if (fwin->titlebar)
423 wCoreDestroy(fwin->titlebar);
425 RemoveFromStackList(fwin->core);
427 wCoreDestroy(fwin->core);
429 if (fwin->title)
430 free(fwin->title);
432 for (i=0; i < (fwin->flags.single_texture ? 1 : 3); i++) {
433 FREE_PIXMAP(fwin->title_back[i]);
434 if (wPreferences.new_style) {
435 FREE_PIXMAP(fwin->lbutton_back[i]);
436 #ifdef XKB_BUTTON_HINT
437 FREE_PIXMAP(fwin->languagebutton_back[i]);
438 #endif
439 FREE_PIXMAP(fwin->rbutton_back[i]);
443 free(fwin);
447 void
448 wFrameWindowChangeState(WFrameWindow *fwin, int state)
450 if (fwin->flags.state==state)
451 return;
453 fwin->flags.state = state;
454 fwin->flags.need_texture_change = 1;
456 wFrameWindowPaint(fwin);
460 static void
461 updateTitlebar(WFrameWindow *fwin)
463 int x, w;
464 int theight;
466 theight = WMFontHeight(*fwin->font) + TITLEBAR_EXTRA_HEIGHT;
468 x = 0;
469 w = fwin->core->width + 1;
471 if (wPreferences.new_style) {
472 if (fwin->flags.hide_left_button || !fwin->left_button
473 || fwin->flags.lbutton_dont_fit) {
474 x = 0;
475 #ifdef XKB_BUTTON_HINT
476 if(fwin->language_button)
477 wCoreConfigure(fwin->language_button, 0, 0,
478 fwin->language_button->width,
479 fwin->language_button->width);
480 #endif
481 } else {
482 #ifdef XKB_BUTTON_HINT
483 if(fwin->language_button)
484 wCoreConfigure(fwin->language_button, fwin->left_button->width, 0,
485 fwin->language_button->width,
486 fwin->language_button->width);
487 #endif
488 x = fwin->left_button->width;
489 w -= fwin->left_button->width;
491 #ifdef XKB_BUTTON_HINT
492 if (fwin->flags.hide_language_button || !fwin->language_button
493 || fwin->flags.languagebutton_dont_fit) {
494 } else {
495 x += fwin->language_button->width;
496 w -= fwin->language_button->width;
498 #endif
500 #ifdef XKB_BUTTON_HINT
501 else {
502 int bsize = theight - 7;
503 if (fwin->flags.hide_left_button || !fwin->left_button
504 || fwin->flags.lbutton_dont_fit) {
505 if(fwin->language_button)
506 wCoreConfigure(fwin->language_button, 3, (theight-bsize)/2,
507 fwin->language_button->width,
508 fwin->language_button->width);
510 else {
511 if(fwin->language_button)
512 wCoreConfigure(fwin->language_button,
513 6 + fwin->left_button->width, (theight-bsize)/2,
514 fwin->language_button->width,
515 fwin->language_button->width);
518 #endif
520 if (wPreferences.new_style) {
521 if (!fwin->flags.hide_right_button && fwin->right_button
522 && !fwin->flags.rbutton_dont_fit) {
523 w -= fwin->right_button->width;
527 if (wPreferences.new_style || fwin->titlebar->width!=w)
528 fwin->flags.need_texture_remake = 1;
530 wCoreConfigure(fwin->titlebar, x, 0, w, theight);
534 void
535 wFrameWindowHideButton(WFrameWindow *fwin, int flags)
537 if ((flags & WFF_RIGHT_BUTTON) && fwin->right_button) {
538 XUnmapWindow(dpy, fwin->right_button->window);
539 fwin->flags.hide_right_button = 1;
542 if ((flags & WFF_LEFT_BUTTON) && fwin->left_button) {
543 XUnmapWindow(dpy, fwin->left_button->window);
544 fwin->flags.hide_left_button = 1;
547 #ifdef XKB_BUTTON_HINT
548 if ((flags & WFF_LANGUAGE_BUTTON) && fwin->language_button) {
549 XUnmapWindow(dpy, fwin->language_button->window);
550 fwin->flags.hide_language_button = 1;
552 #endif
554 if (fwin->titlebar) {
555 if (wPreferences.new_style) {
556 updateTitlebar(fwin);
557 } else {
558 #ifdef XKB_BUTTON_HINT
559 updateTitlebar(fwin);
560 #else
561 XClearWindow(dpy, fwin->titlebar->window);
562 wFrameWindowPaint(fwin);
563 #endif
565 checkTitleSize(fwin);
570 void
571 wFrameWindowShowButton(WFrameWindow *fwin, int flags)
573 if ((flags & WFF_RIGHT_BUTTON) && fwin->right_button
574 && fwin->flags.hide_right_button) {
576 if (!fwin->flags.rbutton_dont_fit)
577 XMapWindow(dpy, fwin->right_button->window);
579 fwin->flags.hide_right_button = 0;
582 #ifdef XKB_BUTTON_HINT
583 if ((flags & WFF_LANGUAGE_BUTTON) && fwin->language_button
584 && fwin->flags.hide_language_button) {
586 if (!fwin->flags.languagebutton_dont_fit)
587 XMapWindow(dpy, fwin->language_button->window);
589 fwin->flags.hide_language_button = 0;
591 #endif
593 if ((flags & WFF_LEFT_BUTTON) && fwin->left_button
594 && fwin->flags.hide_left_button) {
596 if (!fwin->flags.lbutton_dont_fit)
597 XMapWindow(dpy, fwin->left_button->window);
599 fwin->flags.hide_left_button = 0;
603 if (fwin->titlebar) {
604 if (wPreferences.new_style) {
605 updateTitlebar(fwin);
606 } else {
607 XClearWindow(dpy, fwin->titlebar->window);
608 wFrameWindowPaint(fwin);
610 checkTitleSize(fwin);
615 static void
616 #ifdef XKB_BUTTON_HINT
617 renderTexture(WScreen *scr, WTexture *texture, int width, int height,
618 int bwidth, int bheight, int left, int language, int right,
619 Pixmap *title, Pixmap *lbutton, Pixmap *languagebutton, Pixmap *rbutton)
620 #else
621 renderTexture(WScreen *scr, WTexture *texture, int width, int height,
622 int bwidth, int bheight, int left, int right,
623 Pixmap *title, Pixmap *lbutton, Pixmap *rbutton)
624 #endif
626 RImage *img;
627 RImage *limg, *rimg, *mimg;
628 #ifdef XKB_BUTTON_HINT
629 RImage *timg;
630 #endif
631 int x, w;
633 *title = None;
634 *lbutton = None;
635 *rbutton = None;
636 #ifdef XKB_BUTTON_HINT
637 *languagebutton = None;
638 #endif
640 img = wTextureRenderImage(texture, width, height, WREL_FLAT);
641 if (!img) {
642 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
643 return;
646 if (wPreferences.new_style) {
647 if (left) {
648 limg = RGetSubImage(img, 0, 0, bwidth, bheight);
649 } else
650 limg = NULL;
652 x = 0;
653 w = img->width;
655 #ifdef XKB_BUTTON_HINT
656 if (language) {
657 timg = RGetSubImage(img, bwidth, 0, bwidth, bheight);
658 } else
659 timg = NULL;
660 #endif
662 if (limg) {
663 RBevelImage(limg, RBEV_RAISED2);
664 if (!RConvertImage(scr->rcontext, limg, lbutton)) {
665 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
667 x += limg->width;
668 w -= limg->width;
669 RDestroyImage(limg);
672 #ifdef XKB_BUTTON_HINT
673 if (timg) {
674 RBevelImage(timg, RBEV_RAISED2);
675 if (!RConvertImage(scr->rcontext, timg, languagebutton)) {
676 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
678 x += timg->width;
679 w -= timg->width;
680 RDestroyImage(timg);
682 #endif
684 if (right) {
685 rimg = RGetSubImage(img, width - bwidth, 0, bwidth, bheight);
686 } else
687 rimg = NULL;
689 if (rimg) {
690 RBevelImage(rimg, RBEV_RAISED2);
691 if (!RConvertImage(scr->rcontext, rimg, rbutton)) {
692 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
694 w -= rimg->width;
695 RDestroyImage(rimg);
698 if (w!=width) {
699 mimg = RGetSubImage(img, x, 0, w, img->height);
700 RBevelImage(mimg, RBEV_RAISED2);
702 if (!RConvertImage(scr->rcontext, mimg, title)) {
703 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
705 RDestroyImage(mimg);
706 } else {
707 RBevelImage(img, RBEV_RAISED2);
709 if (!RConvertImage(scr->rcontext, img, title)) {
710 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
713 } else {
714 RBevelImage(img, RBEV_RAISED2);
716 if (!RConvertImage(scr->rcontext, img, title)) {
717 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
721 RDestroyImage(img);
725 static void
726 renderResizebarTexture(WScreen *scr, WTexture *texture, int width, int height,
727 int cwidth, Pixmap *pmap)
729 RImage *img;
730 RColor light;
731 RColor dark;
733 *pmap = None;
735 img = wTextureRenderImage(texture, width, height, WREL_FLAT);
736 if (!img) {
737 wwarning(_("could not render texture: %s"),
738 RMessageForError(RErrorCode));
739 return;
742 light.alpha = 0;
743 light.red = light.green = light.blue = 80;
745 dark.alpha = 0;
746 dark.red = dark.green = dark.blue = 40;
748 ROperateLine(img, RSubtractOperation, 0, 0, width-1, 0, &dark);
749 ROperateLine(img, RAddOperation, 0, 1, width-1, 1, &light);
751 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height-1, &dark);
752 ROperateLine(img, RAddOperation, cwidth+1, 2, cwidth+1, height-1, &light);
754 if (width > 1)
755 ROperateLine(img, RSubtractOperation, width-cwidth-2, 2,
756 width-cwidth-2, height-1, &dark);
757 ROperateLine(img, RAddOperation, width-cwidth-1, 2, width-cwidth-1,
758 height-1, &light);
760 #ifdef SHADOW_RESIZEBAR
761 ROperateLine(img, RAddOperation, 0, 1, 0, height-1, &light);
762 ROperateLine(img, RSubtractOperation, width-1, 1, width-1, height-1,
763 &dark);
764 ROperateLine(img, RSubtractOperation, 0, height-1, width-1, height-1,
765 &dark);
766 #endif /* SHADOW_RESIZEBAR */
769 if (!RConvertImage(scr->rcontext, img, pmap)) {
770 wwarning(_("error rendering image: %s"), RMessageForError(RErrorCode));
773 RDestroyImage(img);
778 static void
779 updateTexture(WFrameWindow *fwin)
781 int i;
782 unsigned long pixel;
784 i = fwin->flags.state;
785 if (fwin->titlebar) {
786 if (fwin->title_texture[i]->any.type!=WTEX_SOLID) {
787 XSetWindowBackgroundPixmap(dpy, fwin->titlebar->window,
788 fwin->title_back[i]);
789 if (wPreferences.new_style) {
790 if (fwin->left_button && fwin->lbutton_back[i])
791 XSetWindowBackgroundPixmap(dpy, fwin->left_button->window,
792 fwin->lbutton_back[i]);
794 #ifdef XKB_BUTTON_HINT
795 if (fwin->language_button && fwin->languagebutton_back[i])
796 XSetWindowBackgroundPixmap(dpy, fwin->language_button->window,
797 fwin->languagebutton_back[i]);
798 #endif
800 if (fwin->right_button && fwin->rbutton_back[i])
801 XSetWindowBackgroundPixmap(dpy, fwin->right_button->window,
802 fwin->rbutton_back[i]);
804 } else {
805 pixel = fwin->title_texture[i]->solid.normal.pixel;
806 XSetWindowBackground(dpy, fwin->titlebar->window, pixel);
807 if (wPreferences.new_style) {
808 if (fwin->left_button)
809 XSetWindowBackground(dpy, fwin->left_button->window,
810 pixel);
811 #ifdef XKB_BUTTON_HINT
812 if (fwin->language_button)
813 XSetWindowBackground(dpy, fwin->language_button->window,
814 pixel);
815 #endif
816 if (fwin->right_button)
817 XSetWindowBackground(dpy, fwin->right_button->window,
818 pixel);
821 XClearWindow(dpy, fwin->titlebar->window);
823 if (fwin->left_button) {
824 XClearWindow(dpy, fwin->left_button->window);
825 handleButtonExpose(&fwin->left_button->descriptor, NULL);
827 #ifdef XKB_BUTTON_HINT
828 if (fwin->language_button) {
829 XClearWindow(dpy, fwin->language_button->window);
830 handleButtonExpose(&fwin->language_button->descriptor, NULL);
832 #endif
833 if (fwin->right_button) {
834 XClearWindow(dpy, fwin->right_button->window);
835 handleButtonExpose(&fwin->right_button->descriptor, NULL);
842 static void
843 remakeTexture(WFrameWindow *fwin, int state)
845 Pixmap pmap, lpmap, rpmap;
846 #ifdef XKB_BUTTON_HINT
847 Pixmap tpmap;
848 #endif
850 if (fwin->title_texture[state] && fwin->titlebar) {
851 FREE_PIXMAP(fwin->title_back[state]);
852 if (wPreferences.new_style) {
853 FREE_PIXMAP(fwin->lbutton_back[state]);
854 FREE_PIXMAP(fwin->rbutton_back[state]);
855 #ifdef XKB_BUTTON_HINT
856 FREE_PIXMAP(fwin->languagebutton_back[state]);
857 #endif
860 if (fwin->title_texture[state]->any.type!=WTEX_SOLID) {
861 int left, right;
862 #ifdef XKB_BUTTON_HINT
863 int language;
864 #endif
865 int width;
867 /* eventually surrounded by if new_style */
868 left = fwin->left_button && !fwin->flags.hide_left_button
869 && !fwin->flags.lbutton_dont_fit;
870 #ifdef XKB_BUTTON_HINT
871 language = fwin->language_button && !fwin->flags.hide_language_button
872 && !fwin->flags.languagebutton_dont_fit;
873 #endif
874 right = fwin->right_button && !fwin->flags.hide_right_button
875 && !fwin->flags.rbutton_dont_fit;
877 width = fwin->core->width+1;
879 #ifdef XKB_BUTTON_HINT
880 renderTexture(fwin->screen_ptr, fwin->title_texture[state],
881 width, fwin->titlebar->height,
882 fwin->titlebar->height, fwin->titlebar->height,
883 left, language, right, &pmap, &lpmap, &tpmap, &rpmap);
884 #else
885 renderTexture(fwin->screen_ptr, fwin->title_texture[state],
886 width, fwin->titlebar->height,
887 fwin->titlebar->height, fwin->titlebar->height,
888 left, right, &pmap, &lpmap, &rpmap);
889 #endif
891 fwin->title_back[state] = pmap;
892 if (wPreferences.new_style) {
893 fwin->lbutton_back[state] = lpmap;
894 fwin->rbutton_back[state] = rpmap;
895 #ifdef XKB_BUTTON_HINT
896 fwin->languagebutton_back[state] = tpmap;
897 #endif
901 if (fwin->resizebar_texture && fwin->resizebar_texture[0]
902 && fwin->resizebar && state == 0) {
904 FREE_PIXMAP(fwin->resizebar_back[0]);
906 if (fwin->resizebar_texture[0]->any.type!=WTEX_SOLID) {
908 renderResizebarTexture(fwin->screen_ptr,
909 fwin->resizebar_texture[0],
910 fwin->resizebar->width,
911 fwin->resizebar->height,
912 fwin->resizebar_corner_width,
913 &pmap);
915 fwin->resizebar_back[0] = pmap;
918 /* this part should be in updateTexture() */
919 if (fwin->resizebar_texture[0]->any.type!=WTEX_SOLID) {
920 XSetWindowBackgroundPixmap(dpy, fwin->resizebar->window,
921 fwin->resizebar_back[0]);
922 } else {
923 XSetWindowBackground(dpy, fwin->resizebar->window,
924 fwin->resizebar_texture[0]->solid.normal.pixel);
926 XClearWindow(dpy, fwin->resizebar->window);
931 void
932 wFrameWindowPaint(WFrameWindow *fwin)
934 if (fwin->flags.is_client_window_frame)
935 fwin->flags.justification = wPreferences.title_justification;
937 if (fwin->flags.need_texture_remake) {
938 int i;
940 fwin->flags.need_texture_remake = 0;
941 fwin->flags.need_texture_change = 0;
943 if (fwin->flags.single_texture) {
944 remakeTexture(fwin, 0);
945 updateTexture(fwin);
946 } else {
947 /* first render the texture for the current state... */
948 remakeTexture(fwin, fwin->flags.state);
949 /* ... and paint it */
950 updateTexture(fwin);
952 for (i=0; i < 3; i++) {
953 if (i!=fwin->flags.state)
954 remakeTexture(fwin, i);
959 if (fwin->flags.need_texture_change) {
960 fwin->flags.need_texture_change = 0;
962 updateTexture(fwin);
965 if (fwin->titlebar && !fwin->flags.repaint_only_resizebar
966 && fwin->title_texture[fwin->flags.state]->any.type==WTEX_SOLID) {
967 wDrawBevel(fwin->titlebar->window, fwin->titlebar->width,
968 fwin->titlebar->height,
969 (WTexSolid*)fwin->title_texture[fwin->flags.state],
970 WREL_RAISED);
973 if (fwin->resizebar && !fwin->flags.repaint_only_titlebar
974 && fwin->resizebar_texture[0]->any.type == WTEX_SOLID) {
975 Window win;
976 int w, h;
977 int cw;
978 GC light_gc, dim_gc;
979 WTexSolid *texture = (WTexSolid*)fwin->resizebar_texture[0];
981 w = fwin->resizebar->width;
982 h = fwin->resizebar->height;
983 cw = fwin->resizebar_corner_width;
984 light_gc = texture->light_gc;
985 dim_gc = texture->dim_gc;
986 win = fwin->resizebar->window;
988 XDrawLine(dpy, win, dim_gc, 0, 0, w, 0);
989 XDrawLine(dpy, win, light_gc, 0, 1, w, 1);
991 XDrawLine(dpy, win, dim_gc, cw, 2, cw, h);
992 XDrawLine(dpy, win, light_gc, cw+1, 2, cw+1, h);
994 XDrawLine(dpy, win, dim_gc, w-cw-2, 2, w-cw-2, h);
995 XDrawLine(dpy, win, light_gc, w-cw-1, 2, w-cw-1, h);
997 #ifdef SHADOW_RESIZEBAR
998 XDrawLine(dpy, win, light_gc, 0, 1, 0, h-1);
999 XDrawLine(dpy, win, dim_gc, w-1, 2, w-1, h-1);
1000 XDrawLine(dpy, win, dim_gc, 1, h-1, cw, h-1);
1001 XDrawLine(dpy, win, dim_gc, cw+2, h-1, w-cw-2, h-1);
1002 XDrawLine(dpy, win, dim_gc, w-cw, h-1, w-1, h-1);
1003 #endif /* SHADOW_RESIZEBAR */
1007 if (fwin->title && fwin->titlebar && !fwin->flags.repaint_only_resizebar) {
1008 int x, w;
1009 int lofs = 6, rofs = 6;
1010 int titlelen;
1011 char *title;
1012 int allButtons = 1;
1015 if (!wPreferences.new_style) {
1016 if (fwin->left_button && !fwin->flags.hide_left_button
1017 && !fwin->flags.lbutton_dont_fit)
1018 lofs += fwin->left_button->width + 3;
1019 else
1020 allButtons = 0;
1022 #ifdef XKB_BUTTON_HINT
1023 if (fwin->language_button && !fwin->flags.hide_language_button
1024 && !fwin->flags.languagebutton_dont_fit)
1025 lofs += fwin->language_button->width;
1026 else
1027 allButtons = 0;
1028 #endif
1030 if (fwin->right_button && !fwin->flags.hide_right_button
1031 && !fwin->flags.rbutton_dont_fit)
1032 rofs += fwin->right_button->width + 3;
1033 else
1034 allButtons = 0;
1037 #ifdef XKB_BUTTON_HINT
1038 fwin->languagebutton_image =
1039 fwin->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
1040 #endif
1042 title = ShrinkString(*fwin->font, fwin->title,
1043 fwin->titlebar->width - lofs - rofs);
1044 titlelen = strlen(title);
1045 w = WMWidthOfString(*fwin->font, title, titlelen);
1047 switch (fwin->flags.justification) {
1048 case WTJ_LEFT:
1049 x = lofs;
1050 break;
1052 case WTJ_RIGHT:
1053 x = fwin->titlebar->width - w - rofs;
1054 break;
1056 default:
1057 if (!allButtons)
1058 x = lofs + (fwin->titlebar->width - w - lofs - rofs) / 2;
1059 else
1060 x = (fwin->titlebar->width - w) / 2;
1061 break;
1064 #ifdef TITLE_TEXT_SHADOW
1065 if(wPreferences.title_shadow){
1066 int shadowx,shadowy;
1067 XSetForeground(dpy, *fwin->title_gc,
1068 fwin->title_pixel[fwin->flags.state+3]);
1069 for(shadowx=0;shadowx<TITLE_TEXT_SHADOW_WIDTH;shadowx++)
1070 for(shadowy=0;shadowy<TITLE_TEXT_SHADOW_HEIGHT;shadowy++)
1071 WMDrawString(scr->wmscreen, fwin->titlebar->window,
1072 *fwin->title_gc, *fwin->font,
1073 x + shadowx + TITLE_TEXT_SHADOW_X_OFFSET,
1074 TITLEBAR_EXTRA_HEIGHT/2
1075 + shadowy + TITLE_TEXT_SHADOW_Y_OFFSET, title,
1076 titlelen);
1078 #endif /* TITLE_TEXT_SHADOW */
1080 XSetForeground(dpy, *fwin->title_gc,
1081 fwin->title_pixel[fwin->flags.state]);
1083 WMDrawString(fwin->screen_ptr->wmscreen, fwin->titlebar->window,
1084 *fwin->title_gc, *fwin->font, x, TITLEBAR_EXTRA_HEIGHT/2,
1085 title, titlelen);
1087 free(title);
1089 if (fwin->left_button)
1090 handleButtonExpose(&fwin->left_button->descriptor, NULL);
1091 if (fwin->right_button)
1092 handleButtonExpose(&fwin->right_button->descriptor, NULL);
1093 #ifdef XKB_BUTTON_HINT
1094 if (fwin->language_button)
1095 handleButtonExpose(&fwin->language_button->descriptor, NULL);
1096 #endif
1101 static void
1102 reconfigure(WFrameWindow *fwin, int x, int y, int width, int height,
1103 Bool dontMove)
1105 int k = (wPreferences.new_style ? 4 : 3);
1106 int resizedHorizontally = 0;
1108 if (dontMove)
1109 XResizeWindow(dpy, fwin->core->window, width, height);
1110 else
1111 XMoveResizeWindow(dpy, fwin->core->window, x, y, width, height);
1114 if (fwin->core->height != height && fwin->resizebar)
1115 XMoveWindow(dpy, fwin->resizebar->window, 0,
1116 height - fwin->resizebar->height);
1118 if (fwin->core->width != width) {
1119 fwin->flags.need_texture_remake = 1;
1120 resizedHorizontally = 1;
1123 fwin->core->width = width;
1124 fwin->core->height = height;
1126 if (fwin->titlebar && resizedHorizontally) {
1127 /* Check if the titlebar is wide enough to hold the buttons.
1128 * Temporarily remove them if can't
1130 if (fwin->left_button) {
1131 if (width < fwin->top_width*k && !fwin->flags.lbutton_dont_fit) {
1133 if (!fwin->flags.hide_left_button) {
1134 XUnmapWindow(dpy, fwin->left_button->window);
1136 fwin->flags.lbutton_dont_fit = 1;
1137 } else if (width >= fwin->top_width*k && fwin->flags.lbutton_dont_fit) {
1139 if (!fwin->flags.hide_left_button) {
1140 XMapWindow(dpy, fwin->left_button->window);
1142 fwin->flags.lbutton_dont_fit = 0;
1146 #ifdef XKB_BUTTON_HINT
1147 if (fwin->language_button) {
1148 if (width < fwin->top_width*k && !fwin->flags.languagebutton_dont_fit) {
1150 if (!fwin->flags.hide_language_button) {
1151 XUnmapWindow(dpy, fwin->language_button->window);
1153 fwin->flags.languagebutton_dont_fit = 1;
1154 } else if (width >= fwin->top_width*k && fwin->flags.languagebutton_dont_fit) {
1156 if (!fwin->flags.hide_language_button) {
1157 XMapWindow(dpy, fwin->language_button->window);
1159 fwin->flags.languagebutton_dont_fit = 0;
1162 #endif
1164 if (fwin->right_button) {
1165 if (width < fwin->top_width*2 && !fwin->flags.rbutton_dont_fit) {
1167 if (!fwin->flags.hide_right_button) {
1168 XUnmapWindow(dpy, fwin->right_button->window);
1170 fwin->flags.rbutton_dont_fit = 1;
1171 } else if (width >= fwin->top_width*2 && fwin->flags.rbutton_dont_fit) {
1173 if (!fwin->flags.hide_right_button) {
1174 XMapWindow(dpy, fwin->right_button->window);
1176 fwin->flags.rbutton_dont_fit = 0;
1180 if (wPreferences.new_style) {
1181 if (fwin->right_button)
1182 XMoveWindow(dpy, fwin->right_button->window,
1183 width - fwin->right_button->width + 1, 0);
1184 } else {
1185 if (fwin->right_button)
1186 XMoveWindow(dpy, fwin->right_button->window,
1187 width - fwin->right_button->width - 3,
1188 (fwin->titlebar->height - fwin->right_button->height)/2);
1190 updateTitlebar(fwin);
1191 checkTitleSize(fwin);
1194 if (fwin->resizebar) {
1195 wCoreConfigure(fwin->resizebar, 0,
1196 fwin->core->height - fwin->resizebar->height,
1197 fwin->core->width, fwin->resizebar->height);
1199 fwin->resizebar_corner_width = RESIZEBAR_CORNER_WIDTH;
1200 if (fwin->core->width < RESIZEBAR_CORNER_WIDTH*2 + RESIZEBAR_MIN_WIDTH) {
1201 fwin->resizebar_corner_width = fwin->core->width/2;
1206 void
1207 wFrameWindowConfigure(WFrameWindow *fwin, int x, int y, int width, int height)
1209 reconfigure(fwin, x, y, width, height, False);
1212 void
1213 wFrameWindowResize(WFrameWindow *fwin, int width, int height)
1215 reconfigure(fwin, 0, 0, width, height, True);
1220 int
1221 wFrameWindowChangeTitle(WFrameWindow *fwin, char *new_title)
1223 /* check if the title is the same as before */
1224 if (fwin->title) {
1225 if (new_title && (strcmp(fwin->title, new_title) == 0)) {
1226 return 0;
1228 } else {
1229 if (!new_title)
1230 return 0;
1233 if (fwin->title)
1234 free(fwin->title);
1236 fwin->title = wstrdup(new_title);
1238 if (fwin->titlebar) {
1239 XClearWindow(dpy, fwin->titlebar->window);
1241 wFrameWindowPaint(fwin);
1243 checkTitleSize(fwin);
1245 return 1;
1249 #ifdef OLWM_HINTS
1250 void
1251 wFrameWindowUpdatePushButton(WFrameWindow *fwin, Bool pushed)
1253 fwin->flags.right_button_pushed_in = pushed;
1255 paintButton(fwin->right_button, fwin->title_texture[fwin->flags.state],
1256 fwin->title_pixel[fwin->flags.state],
1257 fwin->rbutton_image, pushed);
1259 #endif /* OLWM_HINTS */
1262 #ifdef XKB_BUTTON_HINT
1263 void
1264 wFrameWindowUpdateLanguageButton(WFrameWindow *fwin)
1266 paintButton(fwin->language_button, fwin->title_texture[fwin->flags.state],
1267 fwin->title_pixel[fwin->flags.state],
1268 fwin->languagebutton_image, True);
1270 #endif /* XKB_BUTTON_HINT */
1273 /*********************************************************************/
1275 static void
1276 handleExpose(WObjDescriptor *desc, XEvent *event)
1278 WFrameWindow *fwin = (WFrameWindow*)desc->parent;
1281 if (fwin->titlebar && fwin->titlebar->window == event->xexpose.window)
1282 fwin->flags.repaint_only_titlebar = 1;
1283 if (fwin->resizebar && fwin->resizebar->window == event->xexpose.window)
1284 fwin->flags.repaint_only_resizebar = 1;
1285 wFrameWindowPaint(fwin);
1286 fwin->flags.repaint_only_titlebar = 0;
1287 fwin->flags.repaint_only_resizebar = 0;
1291 static void
1292 checkTitleSize(WFrameWindow *fwin)
1294 int width;
1296 if (!fwin->title) {
1297 fwin->flags.incomplete_title = 0;
1298 return;
1301 if (!fwin->titlebar) {
1302 fwin->flags.incomplete_title = 1;
1303 return;
1304 } else {
1305 width = fwin->titlebar->width - 6 - 6;
1308 if (!wPreferences.new_style) {
1309 if (fwin->left_button && !fwin->flags.hide_left_button
1310 && !fwin->flags.lbutton_dont_fit)
1311 width -= fwin->left_button->width + 3;
1313 #ifdef XKB_BUTTON_HINT
1314 if (fwin->language_button && !fwin->flags.hide_language_button
1315 && !fwin->flags.languagebutton_dont_fit)
1316 width -= fwin->language_button->width + 3;
1317 #endif
1319 if (fwin->right_button && !fwin->flags.hide_right_button
1320 && !fwin->flags.rbutton_dont_fit)
1321 width -= fwin->right_button->width + 3;
1323 if (WMWidthOfString(*fwin->font, fwin->title, strlen(fwin->title)) > width) {
1324 fwin->flags.incomplete_title = 1;
1325 } else {
1326 fwin->flags.incomplete_title = 0;
1331 static void
1332 paintButton(WCoreWindow *button, WTexture *texture, unsigned long color,
1333 WPixmap *image, int pushed)
1335 WScreen *scr = button->screen_ptr;
1336 GC copy_gc = scr->copy_gc;
1337 int x=0, y=0, d=0;
1338 int left=0, width=0;
1340 /* setup stuff according to the state */
1341 if (pushed) {
1342 if (image) {
1343 if (image->width>=image->height*2) {
1344 /* the image contains 2 pictures: the second is for the
1345 * pushed state */
1346 width = image->width/2;
1347 left = image->width/2;
1348 } else {
1349 width = image->width;
1352 XSetClipMask(dpy, copy_gc, None);
1353 XSetForeground(dpy, copy_gc, scr->white_pixel);
1354 d=1;
1355 if (wPreferences.new_style) {
1356 XFillRectangle(dpy, button->window, copy_gc, 0, 0,
1357 button->width-1, button->height-1);
1358 XSetForeground(dpy, copy_gc, scr->black_pixel);
1359 XDrawRectangle(dpy, button->window, copy_gc, 0, 0,
1360 button->width-1, button->height-1);
1361 } else {
1362 XFillRectangle(dpy, button->window, copy_gc, 0, 0,
1363 button->width, button->height);
1364 XSetForeground(dpy, copy_gc, scr->black_pixel);
1365 XDrawRectangle(dpy, button->window, copy_gc, 0, 0,
1366 button->width, button->height);
1368 } else {
1369 XClearWindow(dpy, button->window);
1371 if (image) {
1372 if (image->width>=image->height*2)
1373 width = image->width/2;
1374 else
1375 width = image->width;
1377 d=0;
1379 if (wPreferences.new_style) {
1380 if (texture->any.type==WTEX_SOLID || pushed) {
1381 wDrawBevel(button->window, button->width, button->height,
1382 (WTexSolid*)texture, WREL_RAISED);
1384 } else {
1385 wDrawBevel(button->window, button->width, button->height,
1386 scr->widget_texture, WREL_RAISED);
1390 if (image) {
1391 /* display image */
1392 XSetClipMask(dpy, copy_gc, image->mask);
1393 x = (button->width - width)/2 + d;
1394 y = (button->height - image->height)/2 + d;
1395 XSetClipOrigin(dpy, copy_gc, x-left, y);
1396 if (!wPreferences.new_style) {
1397 XSetForeground(dpy, copy_gc, scr->black_pixel);
1398 if (!pushed) {
1399 if (image->depth==1)
1400 XCopyPlane(dpy, image->image, button->window, copy_gc,
1401 left, 0, width, image->height, x, y, 1);
1402 else
1403 XCopyArea(dpy, image->image, button->window, copy_gc,
1404 left, 0, width, image->height, x, y);
1405 } else {
1406 XSetForeground(dpy, copy_gc, scr->dark_pixel);
1407 XFillRectangle(dpy, button->window, copy_gc, 0, 0,
1408 button->width, button->height);
1410 } else {
1411 if (pushed) {
1412 XSetForeground(dpy, copy_gc, scr->black_pixel);
1413 } else {
1414 XSetForeground(dpy, copy_gc, color);
1415 XSetBackground(dpy, copy_gc, texture->any.color.pixel);
1417 XFillRectangle(dpy, button->window, copy_gc, 0, 0,
1418 button->width, button->height);
1424 static void
1425 handleButtonExpose(WObjDescriptor *desc, XEvent *event)
1427 WFrameWindow *fwin = (WFrameWindow*)desc->parent;
1428 WCoreWindow *button = (WCoreWindow*)desc->self;
1430 #ifdef XKB_BUTTON_HINT
1431 if (button == fwin->language_button) {
1432 if (wPreferences.modelock){
1433 paintButton(button, fwin->title_texture[fwin->flags.state],
1434 fwin->title_pixel[fwin->flags.state],
1435 fwin->languagebutton_image, False);
1437 } else
1438 #endif
1439 if (button == fwin->left_button) {
1440 paintButton(button, fwin->title_texture[fwin->flags.state],
1441 fwin->title_pixel[fwin->flags.state],
1442 fwin->lbutton_image, False);
1443 } else {
1444 Bool pushed = False;
1446 #ifdef OLWM_HINTS
1447 if (fwin->flags.right_button_pushed_in)
1448 pushed = True;
1449 #endif
1450 /* emulate the olwm pushpin in the "out" state */
1451 paintButton(button, fwin->title_texture[fwin->flags.state],
1452 fwin->title_pixel[fwin->flags.state],
1453 fwin->rbutton_image, pushed);
1458 static void
1459 titlebarMouseDown(WObjDescriptor *desc, XEvent *event)
1461 WFrameWindow *fwin = desc->parent;
1462 WCoreWindow *titlebar = desc->self;
1464 if (IsDoubleClick(fwin->core->screen_ptr, event)) {
1465 if (fwin->on_dblclick_titlebar)
1466 (*fwin->on_dblclick_titlebar)(titlebar, fwin->child, event);
1467 } else {
1468 if (fwin->on_mousedown_titlebar)
1469 (*fwin->on_mousedown_titlebar)(titlebar, fwin->child, event);
1474 static void
1475 resizebarMouseDown(WObjDescriptor *desc, XEvent *event)
1477 WFrameWindow *fwin = desc->parent;
1478 WCoreWindow *resizebar = desc->self;
1480 if (fwin->on_mousedown_resizebar)
1481 (*fwin->on_mousedown_resizebar)(resizebar, fwin->child, event);
1485 static void
1486 buttonMouseDown(WObjDescriptor *desc, XEvent *event)
1488 WFrameWindow *fwin = desc->parent;
1489 WCoreWindow *button = desc->self;
1490 WPixmap *image;
1491 XEvent ev;
1492 int done=0, execute=1;
1493 WTexture *texture;
1494 unsigned long pixel;
1495 int clickButton = event->xbutton.button;
1497 if (IsDoubleClick(fwin->core->screen_ptr, event)) {
1498 if (button == fwin->right_button && fwin->on_dblclick_right) {
1499 (*fwin->on_dblclick_right)(button, fwin->child, event);
1501 return;
1504 if (button == fwin->left_button) {
1505 image = fwin->lbutton_image;
1506 } else {
1507 image = fwin->rbutton_image;
1509 #ifdef XKB_BUTTON_HINT
1510 if (button == fwin->language_button) {
1511 if (!wPreferences.modelock) return;
1512 image = fwin->languagebutton_image;
1514 #endif
1516 pixel = fwin->title_pixel[fwin->flags.state];
1517 texture = fwin->title_texture[fwin->flags.state];
1518 paintButton(button, texture, pixel, image, True);
1520 while (!done) {
1521 WMMaskEvent(dpy, LeaveWindowMask|EnterWindowMask|ButtonReleaseMask
1522 |ButtonPressMask|ExposureMask, &ev);
1523 switch (ev.type) {
1524 case LeaveNotify:
1525 execute = 0;
1526 paintButton(button, texture, pixel, image, False);
1527 break;
1529 case EnterNotify:
1530 execute = 1;
1531 paintButton(button, texture, pixel, image, True);
1532 break;
1534 case ButtonPress:
1535 break;
1537 case ButtonRelease:
1538 if (ev.xbutton.button == clickButton)
1539 done = 1;
1540 break;
1542 default:
1543 WMHandleEvent(&ev);
1546 paintButton(button, texture, pixel, image, False);
1548 if (execute) {
1549 if (button == fwin->left_button) {
1550 if (fwin->on_click_left)
1551 (*fwin->on_click_left)(button, fwin->child, &ev);
1552 } else if (button == fwin->right_button) {
1553 if (fwin->on_click_right)
1554 (*fwin->on_click_right)(button, fwin->child, &ev);
1556 #ifdef XKB_BUTTON_HINT
1557 else if (button == fwin->language_button) {
1558 if (fwin->on_click_language)
1559 (*fwin->on_click_language)(button, fwin->child, &ev);
1561 #endif