wmaker: Replaced local 'extern' definition of wPreferences by proper header usage
[wmaker-crm.git] / src / framewin.c
blob91572951a63b44f19957a575e04448b7adca068a
1 /*
2 * Window Maker window manager
4 * Copyright (c) 1997-2003 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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "wconfig.h"
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25 #ifdef KEEP_XKB_LOCK_STATUS
26 #include <X11/XKBlib.h>
27 #endif /* KEEP_XKB_LOCK_STATUS */
29 #include <stdlib.h>
30 #include <string.h>
32 #include <wraster.h>
34 #include "WindowMaker.h"
35 #include "GNUstep.h"
36 #include "texture.h"
37 #include "resources.h"
38 #include "screen.h"
39 #include "wcore.h"
40 #include "window.h"
41 #include "framewin.h"
42 #include "stacking.h"
43 #include "misc.h"
44 #include "event.h"
46 #define DBLCLICK_TIME wPreferences.dblclick_time
49 static void handleExpose(WObjDescriptor * desc, XEvent * event);
50 static void handleButtonExpose(WObjDescriptor * desc, XEvent * event);
52 static void buttonMouseDown(WObjDescriptor * desc, XEvent * event);
53 static void titlebarMouseDown(WObjDescriptor * desc, XEvent * event);
54 static void resizebarMouseDown(WObjDescriptor * desc, XEvent * event);
56 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);
63 static void allocFrameBorderPixel(Colormap colormap, const char *color_name, unsigned long **pixel);
65 static void allocFrameBorderPixel(Colormap colormap, const char *color_name, unsigned long **pixel) {
66 XColor xcol;
68 *pixel = NULL;
70 if (! wGetColorForColormap(colormap, color_name, &xcol))
71 return;
73 *pixel = wmalloc(sizeof(unsigned long));
74 if (*pixel)
75 **pixel = xcol.pixel;
78 WFrameWindow *wFrameWindowCreate(WScreen * scr, int wlevel, int x, int y,
79 int width, int height, int *clearance,
80 int *title_min, int *title_max, int flags,
81 WTexture ** title_texture, WTexture ** resize_texture,
82 WMColor ** color, WMFont ** font,
83 int depth, Visual *visual, Colormap colormap)
85 WFrameWindow *fwin;
87 fwin = wmalloc(sizeof(WFrameWindow));
89 fwin->screen_ptr = scr;
91 fwin->flags.single_texture = (flags & WFF_SINGLE_STATE) ? 1 : 0;
93 fwin->title_texture = title_texture;
94 fwin->resizebar_texture = resize_texture;
95 fwin->title_color = color;
96 fwin->title_clearance = clearance;
97 fwin->title_min_height = title_min;
98 fwin->title_max_height = title_max;
99 fwin->font = font;
100 #ifdef KEEP_XKB_LOCK_STATUS
101 fwin->languagemode = XkbGroup1Index;
102 fwin->last_languagemode = XkbGroup2Index;
103 #endif
105 fwin->depth = depth;
106 fwin->visual = visual;
107 fwin->colormap = colormap;
109 fwin->core = wCoreCreateTopLevel(scr, x, y, width, height, (flags & WFF_BORDER)
110 ? scr->frame_border_width : 0, fwin->depth, fwin->visual, fwin->colormap, scr->frame_border_pixel);
112 /* setup stacking information */
113 fwin->core->stacking = wmalloc(sizeof(WStacking));
114 fwin->core->stacking->above = NULL;
115 fwin->core->stacking->under = NULL;
116 fwin->core->stacking->child_of = NULL;
117 fwin->core->stacking->window_level = wlevel;
119 AddToStackList(fwin->core);
121 wFrameWindowUpdateBorders(fwin, flags);
123 return fwin;
126 void wFrameWindowUpdateBorders(WFrameWindow * fwin, int flags)
128 int theight;
129 int bsize;
130 int width, height;
131 int i;
132 WScreen *scr = fwin->screen_ptr;
134 width = fwin->core->width;
135 if (flags & WFF_IS_SHADED)
136 height = -1;
137 else
138 height = fwin->core->height - fwin->top_width - fwin->bottom_width;
140 if (flags & WFF_TITLEBAR) {
141 theight = WMFontHeight(*fwin->font) + (*fwin->title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
143 if (theight > *fwin->title_max_height)
144 theight = *fwin->title_max_height;
146 if (theight < *fwin->title_min_height)
147 theight = *fwin->title_min_height;
148 } else {
149 theight = 0;
152 if (wPreferences.new_style == TS_NEW) {
153 bsize = theight;
154 } else if (wPreferences.new_style == TS_OLD) {
155 bsize = theight - 7;
156 } else {
157 bsize = theight - 8;
160 if (fwin->titlebar) {
161 /* if we had a titlebar and is requesting for one,
162 * check if the size has changed and resize it */
163 if (flags & WFF_TITLEBAR) {
164 fwin->top_width = theight;
166 fwin->flags.need_texture_remake = 1;
168 if (wPreferences.new_style == TS_NEW) {
169 if (fwin->left_button)
170 wCoreConfigure(fwin->left_button, 0, 0, bsize, bsize);
171 #ifdef XKB_BUTTON_HINT
172 if (fwin->language_button) {
173 if (fwin->flags.hide_left_button || !fwin->left_button
174 || fwin->flags.lbutton_dont_fit)
175 wCoreConfigure(fwin->language_button, 0, 0, bsize, bsize);
176 else
177 wCoreConfigure(fwin->language_button, bsize, 0, bsize, bsize);
179 #endif
181 if (fwin->right_button)
182 wCoreConfigure(fwin->right_button, width - bsize + 1, 0, bsize, bsize);
184 } else { /* !new_style */
185 if (fwin->left_button)
186 wCoreConfigure(fwin->left_button, 3, (theight - bsize) / 2, bsize, bsize);
187 #ifdef XKB_BUTTON_HINT
188 if (fwin->language_button)
189 wCoreConfigure(fwin->language_button, 6 + bsize, (theight - bsize) / 2,
190 bsize, bsize);
191 #endif
193 if (fwin->right_button)
194 wCoreConfigure(fwin->right_button, width - bsize - 3,
195 (theight - bsize) / 2, bsize, bsize);
197 updateTitlebar(fwin);
198 } else {
199 /* we had a titlebar, but now we don't need it anymore */
200 for (i = 0; i < (fwin->flags.single_texture ? 1 : 3); i++) {
201 FREE_PIXMAP(fwin->title_back[i]);
202 if (wPreferences.new_style == TS_NEW) {
203 FREE_PIXMAP(fwin->lbutton_back[i]);
204 FREE_PIXMAP(fwin->rbutton_back[i]);
205 #ifdef XKB_BUTTON_HINT
206 FREE_PIXMAP(fwin->languagebutton_back[i]);
207 #endif
210 if (fwin->left_button)
211 wCoreDestroy(fwin->left_button);
212 fwin->left_button = NULL;
214 #ifdef XKB_BUTTON_HINT
215 if (fwin->language_button)
216 wCoreDestroy(fwin->language_button);
217 fwin->language_button = NULL;
218 #endif
220 if (fwin->right_button)
221 wCoreDestroy(fwin->right_button);
222 fwin->right_button = NULL;
224 wCoreDestroy(fwin->titlebar);
225 fwin->titlebar = NULL;
227 fwin->top_width = 0;
229 } else {
230 /* if we didn't have a titlebar and are being requested for
231 * one, create it */
232 if (flags & WFF_TITLEBAR) {
233 fwin->top_width = theight;
235 fwin->flags.titlebar = 1;
236 fwin->titlebar = wCoreCreate(fwin->core, 0, 0, width + 1, theight);
238 if (flags & WFF_LEFT_BUTTON) {
239 fwin->flags.left_button = 1;
240 if (wPreferences.new_style == TS_NEW) {
241 fwin->left_button = wCoreCreate(fwin->core, 0, 0, bsize, bsize);
243 if (width < theight * 4)
244 fwin->flags.lbutton_dont_fit = 1;
245 else
246 XMapRaised(dpy, fwin->left_button->window);
248 } else if (wPreferences.new_style == TS_OLD) {
249 fwin->left_button =
250 wCoreCreate(fwin->titlebar, 3, (theight - bsize) / 2, bsize, bsize);
252 XSetWindowBackground(dpy, fwin->left_button->window,
253 scr->widget_texture->normal.pixel);
255 if (width < theight * 3)
256 fwin->flags.lbutton_dont_fit = 1;
257 else
258 XMapRaised(dpy, fwin->left_button->window);
260 } else {
261 fwin->left_button =
262 wCoreCreate(fwin->titlebar, 3, (theight-bsize)/2,
263 bsize, bsize);
265 XSetWindowBackground(dpy, fwin->left_button->window,
266 scr->widget_texture->dark.pixel);
268 if (width < theight * 3)
269 fwin->flags.lbutton_dont_fit = 1;
270 else
271 XMapRaised(dpy, fwin->left_button->window);
275 #ifdef XKB_BUTTON_HINT
276 if (flags & WFF_LANGUAGE_BUTTON) {
277 fwin->flags.language_button = 1;
278 if (wPreferences.new_style == TS_NEW) {
279 fwin->language_button = wCoreCreate(fwin->core, bsize, 0, bsize, bsize);
281 if (width < theight * 4)
282 fwin->flags.languagebutton_dont_fit = 1;
283 else
284 XMapRaised(dpy, fwin->language_button->window);
285 } else {
286 fwin->language_button =
287 wCoreCreate(fwin->titlebar, bsize + 6, (theight - bsize) / 2,
288 bsize, bsize);
290 XSetWindowBackground(dpy, fwin->language_button->window,
291 scr->widget_texture->normal.pixel);
293 if (width < theight * 3)
294 fwin->flags.languagebutton_dont_fit = 1;
295 else
296 XMapRaised(dpy, fwin->language_button->window);
299 #endif
301 if (flags & WFF_RIGHT_BUTTON) {
302 fwin->flags.right_button = 1;
303 if (wPreferences.new_style == TS_NEW) {
304 fwin->right_button =
305 wCoreCreate(fwin->core, width - bsize + 1, 0, bsize, bsize);
306 } else if (wPreferences.new_style == TS_OLD) {
307 fwin->right_button =
308 wCoreCreate(fwin->titlebar, width - bsize - 3,
309 (theight - bsize) / 2, bsize, bsize);
310 XSetWindowBackground(dpy, fwin->right_button->window,
311 scr->widget_texture->normal.pixel);
312 } else {
313 fwin->right_button =
314 wCoreCreate(fwin->titlebar, width-bsize-3,
315 (theight-bsize)/2, bsize, bsize);
316 XSetWindowBackground(dpy, fwin->right_button->window,
317 scr->widget_texture->dark.pixel);
320 if (width < theight * 2)
321 fwin->flags.rbutton_dont_fit = 1;
322 else
323 XMapRaised(dpy, fwin->right_button->window);
326 if (wPreferences.new_style == TS_NEW)
327 updateTitlebar(fwin);
329 XMapRaised(dpy, fwin->titlebar->window);
331 fwin->flags.need_texture_remake = 1;
334 checkTitleSize(fwin);
336 if (flags & WFF_RESIZEBAR) {
337 fwin->bottom_width = RESIZEBAR_HEIGHT;
339 if (!fwin->resizebar) {
340 fwin->flags.resizebar = 1;
341 fwin->resizebar = wCoreCreate(fwin->core, 0,
342 height + fwin->top_width, width, RESIZEBAR_HEIGHT);
343 fwin->resizebar_corner_width = RESIZEBAR_CORNER_WIDTH;
344 if (width < RESIZEBAR_CORNER_WIDTH * 2 + RESIZEBAR_MIN_WIDTH) {
345 fwin->resizebar_corner_width = (width - RESIZEBAR_MIN_WIDTH) / 2;
346 if (fwin->resizebar_corner_width < 0)
347 fwin->resizebar_corner_width = 0;
350 XMapWindow(dpy, fwin->resizebar->window);
351 XLowerWindow(dpy, fwin->resizebar->window);
353 fwin->flags.need_texture_remake = 1;
354 } else {
355 if (height + fwin->top_width + fwin->bottom_width != fwin->core->height)
356 wCoreConfigure(fwin->resizebar, 0, height + fwin->top_width,
357 width, RESIZEBAR_HEIGHT);
359 } else {
360 fwin->bottom_width = 0;
362 if (fwin->resizebar) {
363 fwin->bottom_width = 0;
364 wCoreDestroy(fwin->resizebar);
365 fwin->resizebar = NULL;
369 if (height + fwin->top_width + fwin->bottom_width != fwin->core->height && !(flags & WFF_IS_SHADED))
370 wFrameWindowResize(fwin, width, height + fwin->top_width + fwin->bottom_width);
372 if (flags & WFF_BORDER)
373 XSetWindowBorderWidth(dpy, fwin->core->window, scr->frame_border_width);
374 else
375 XSetWindowBorderWidth(dpy, fwin->core->window, 0);
377 /* setup object descriptors */
378 if (fwin->titlebar) {
379 fwin->titlebar->descriptor.handle_expose = handleExpose;
380 fwin->titlebar->descriptor.parent = fwin;
381 fwin->titlebar->descriptor.parent_type = WCLASS_FRAME;
382 fwin->titlebar->descriptor.handle_mousedown = titlebarMouseDown;
385 if (fwin->resizebar) {
386 fwin->resizebar->descriptor.handle_expose = handleExpose;
387 fwin->resizebar->descriptor.parent = fwin;
388 fwin->resizebar->descriptor.parent_type = WCLASS_FRAME;
389 fwin->resizebar->descriptor.handle_mousedown = resizebarMouseDown;
392 if (fwin->left_button) {
393 fwin->left_button->descriptor.handle_expose = handleButtonExpose;
394 fwin->left_button->descriptor.parent = fwin;
395 fwin->left_button->descriptor.parent_type = WCLASS_FRAME;
396 fwin->left_button->descriptor.handle_mousedown = buttonMouseDown;
399 #ifdef XKB_BUTTON_HINT
400 if (fwin->language_button) {
401 fwin->language_button->descriptor.handle_expose = handleButtonExpose;
402 fwin->language_button->descriptor.parent = fwin;
403 fwin->language_button->descriptor.parent_type = WCLASS_FRAME;
404 fwin->language_button->descriptor.handle_mousedown = buttonMouseDown;
406 #endif
408 if (fwin->right_button) {
409 fwin->right_button->descriptor.parent = fwin;
410 fwin->right_button->descriptor.parent_type = WCLASS_FRAME;
411 fwin->right_button->descriptor.handle_expose = handleButtonExpose;
412 fwin->right_button->descriptor.handle_mousedown = buttonMouseDown;
415 checkTitleSize(fwin);
417 allocFrameBorderPixel(fwin->colormap, WMGetColorRGBDescription(scr->frame_border_color), &fwin->border_pixel);
418 allocFrameBorderPixel(fwin->colormap, WMGetColorRGBDescription(scr->frame_selected_border_color), &fwin->selected_border_pixel);
420 if (flags & WFF_SELECTED) {
421 if (fwin->selected_border_pixel)
422 XSetWindowBorder(dpy, fwin->core->window, *fwin->selected_border_pixel);
424 else {
425 if (fwin->border_pixel)
426 XSetWindowBorder(dpy, fwin->core->window, *fwin->border_pixel);
430 void wFrameWindowDestroy(WFrameWindow * fwin)
432 int i;
434 if (fwin->left_button)
435 wCoreDestroy(fwin->left_button);
437 #ifdef XKB_BUTTON_HINT
438 if (fwin->language_button)
439 wCoreDestroy(fwin->language_button);
440 #endif
442 if (fwin->right_button)
443 wCoreDestroy(fwin->right_button);
445 if (fwin->resizebar)
446 wCoreDestroy(fwin->resizebar);
448 if (fwin->titlebar)
449 wCoreDestroy(fwin->titlebar);
451 RemoveFromStackList(fwin->core);
453 wCoreDestroy(fwin->core);
455 if (fwin->title)
456 wfree(fwin->title);
458 for (i = 0; i < (fwin->flags.single_texture ? 1 : 3); i++) {
459 FREE_PIXMAP(fwin->title_back[i]);
460 if (wPreferences.new_style == TS_NEW) {
461 FREE_PIXMAP(fwin->lbutton_back[i]);
462 #ifdef XKB_BUTTON_HINT
463 FREE_PIXMAP(fwin->languagebutton_back[i]);
464 #endif
465 FREE_PIXMAP(fwin->rbutton_back[i]);
469 wfree(fwin);
472 void wFrameWindowChangeState(WFrameWindow * fwin, int state)
474 if (fwin->flags.state == state)
475 return;
477 fwin->flags.state = state;
478 fwin->flags.need_texture_change = 1;
480 wFrameWindowPaint(fwin);
483 static void updateTitlebar(WFrameWindow * fwin)
485 int x, w;
486 int theight;
488 theight = WMFontHeight(*fwin->font) + (*fwin->title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
490 if (theight > *fwin->title_max_height)
491 theight = *fwin->title_max_height;
493 if (theight < *fwin->title_min_height)
494 theight = *fwin->title_min_height;
496 x = 0;
497 w = fwin->core->width + 1;
499 if (wPreferences.new_style == TS_NEW) {
500 if (fwin->flags.hide_left_button || !fwin->left_button || fwin->flags.lbutton_dont_fit) {
501 x = 0;
502 #ifdef XKB_BUTTON_HINT
503 if (fwin->language_button)
504 wCoreConfigure(fwin->language_button, 0, 0,
505 fwin->language_button->width, fwin->language_button->width);
506 #endif
507 } else {
508 #ifdef XKB_BUTTON_HINT
509 if (fwin->language_button)
510 wCoreConfigure(fwin->language_button, fwin->left_button->width, 0,
511 fwin->language_button->width, fwin->language_button->width);
512 #endif
513 x = fwin->left_button->width;
514 w -= fwin->left_button->width;
516 #ifdef XKB_BUTTON_HINT
517 if (fwin->flags.hide_language_button || !fwin->language_button
518 || fwin->flags.languagebutton_dont_fit) {
519 } else {
520 x += fwin->language_button->width;
521 w -= fwin->language_button->width;
523 #endif
525 #ifdef XKB_BUTTON_HINT
526 else {
527 int bsize = theight - 7;
528 if (fwin->flags.hide_left_button || !fwin->left_button || fwin->flags.lbutton_dont_fit) {
529 if (fwin->language_button)
530 wCoreConfigure(fwin->language_button, 3, (theight - bsize) / 2,
531 fwin->language_button->width, fwin->language_button->width);
532 } else {
533 if (fwin->language_button)
534 wCoreConfigure(fwin->language_button,
535 6 + fwin->left_button->width, (theight - bsize) / 2,
536 fwin->language_button->width, fwin->language_button->width);
539 #endif
541 if (wPreferences.new_style == TS_NEW) {
542 if (!fwin->flags.hide_right_button && fwin->right_button && !fwin->flags.rbutton_dont_fit)
543 w -= fwin->right_button->width;
546 if (wPreferences.new_style == TS_NEW || fwin->titlebar->width != w)
547 fwin->flags.need_texture_remake = 1;
549 wCoreConfigure(fwin->titlebar, x, 0, w, theight);
552 void wFrameWindowHideButton(WFrameWindow * fwin, int flags)
554 if ((flags & WFF_RIGHT_BUTTON) && fwin->right_button) {
555 XUnmapWindow(dpy, fwin->right_button->window);
556 fwin->flags.hide_right_button = 1;
559 if ((flags & WFF_LEFT_BUTTON) && fwin->left_button) {
560 XUnmapWindow(dpy, fwin->left_button->window);
561 fwin->flags.hide_left_button = 1;
563 #ifdef XKB_BUTTON_HINT
564 if ((flags & WFF_LANGUAGE_BUTTON) && fwin->language_button) {
565 XUnmapWindow(dpy, fwin->language_button->window);
566 fwin->flags.hide_language_button = 1;
568 #endif
570 if (fwin->titlebar) {
571 if (wPreferences.new_style == TS_NEW) {
572 updateTitlebar(fwin);
573 } else {
574 #ifdef XKB_BUTTON_HINT
575 updateTitlebar(fwin);
576 #else
577 XClearWindow(dpy, fwin->titlebar->window);
578 wFrameWindowPaint(fwin);
579 #endif
581 checkTitleSize(fwin);
585 void wFrameWindowShowButton(WFrameWindow * fwin, int flags)
587 if ((flags & WFF_RIGHT_BUTTON) && fwin->right_button && fwin->flags.hide_right_button) {
589 if (!fwin->flags.rbutton_dont_fit)
590 XMapWindow(dpy, fwin->right_button->window);
592 fwin->flags.hide_right_button = 0;
594 #ifdef XKB_BUTTON_HINT
595 if ((flags & WFF_LANGUAGE_BUTTON) && fwin->language_button && fwin->flags.hide_language_button) {
597 if (!fwin->flags.languagebutton_dont_fit)
598 XMapWindow(dpy, fwin->language_button->window);
600 fwin->flags.hide_language_button = 0;
602 #endif
604 if ((flags & WFF_LEFT_BUTTON) && fwin->left_button && fwin->flags.hide_left_button) {
606 if (!fwin->flags.lbutton_dont_fit)
607 XMapWindow(dpy, fwin->left_button->window);
609 fwin->flags.hide_left_button = 0;
612 if (fwin->titlebar) {
613 if (wPreferences.new_style == TS_NEW) {
614 updateTitlebar(fwin);
615 } else {
616 XClearWindow(dpy, fwin->titlebar->window);
617 wFrameWindowPaint(fwin);
619 checkTitleSize(fwin);
623 static void
624 #ifdef XKB_BUTTON_HINT
625 renderTexture(WScreen * scr, WTexture * texture, int width, int height,
626 int bwidth, int bheight, int left, int language, int right,
627 Pixmap * title, Pixmap * lbutton, Pixmap * languagebutton, Pixmap * rbutton)
628 #else
629 renderTexture(WScreen * scr, WTexture * texture, int width, int height,
630 int bwidth, int bheight, int left, int right, Pixmap * title, Pixmap * lbutton, Pixmap * rbutton)
631 #endif
633 RImage *img;
634 RImage *limg, *rimg, *mimg;
635 #ifdef XKB_BUTTON_HINT
636 RImage *timg;
637 #endif
638 int x, w;
640 *title = None;
641 *lbutton = None;
642 *rbutton = None;
643 #ifdef XKB_BUTTON_HINT
644 *languagebutton = None;
645 #endif
647 img = wTextureRenderImage(texture, width, height, WREL_FLAT);
648 if (!img) {
649 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
650 return;
653 if (wPreferences.new_style == TS_NEW) {
654 if (left)
655 limg = RGetSubImage(img, 0, 0, bwidth, bheight);
656 else
657 limg = NULL;
659 x = 0;
660 w = img->width;
662 #ifdef XKB_BUTTON_HINT
663 if (language)
664 timg = RGetSubImage(img, bwidth * left, 0, bwidth, bheight);
665 else
666 timg = NULL;
667 #endif
669 if (limg) {
670 RBevelImage(limg, RBEV_RAISED2);
671 if (!RConvertImage(scr->rcontext, limg, lbutton))
672 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
674 x += limg->width;
675 w -= limg->width;
676 RReleaseImage(limg);
678 #ifdef XKB_BUTTON_HINT
679 if (timg) {
680 RBevelImage(timg, RBEV_RAISED2);
681 if (!RConvertImage(scr->rcontext, timg, languagebutton))
682 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
684 x += timg->width;
685 w -= timg->width;
686 RReleaseImage(timg);
688 #endif
690 if (right)
691 rimg = RGetSubImage(img, width - bwidth, 0, bwidth, bheight);
692 else
693 rimg = NULL;
695 if (rimg) {
696 RBevelImage(rimg, RBEV_RAISED2);
697 if (!RConvertImage(scr->rcontext, rimg, rbutton))
698 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
700 w -= rimg->width;
701 RReleaseImage(rimg);
704 if (w != width) {
705 mimg = RGetSubImage(img, x, 0, w, img->height);
706 RBevelImage(mimg, RBEV_RAISED2);
708 if (!RConvertImage(scr->rcontext, mimg, title))
709 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
711 RReleaseImage(mimg);
712 } else {
713 RBevelImage(img, RBEV_RAISED2);
715 if (!RConvertImage(scr->rcontext, img, title))
716 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
718 } else {
719 RBevelImage(img, RBEV_RAISED2);
721 if (!RConvertImage(scr->rcontext, img, title))
722 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
725 RReleaseImage(img);
728 static void
729 renderResizebarTexture(WScreen * scr, WTexture * texture, int width, int height, int cwidth, Pixmap * pmap)
731 RImage *img;
732 RColor light;
733 RColor dark;
735 *pmap = None;
737 img = wTextureRenderImage(texture, width, height, WREL_FLAT);
738 if (!img) {
739 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
740 return;
743 light.alpha = 0;
744 light.red = light.green = light.blue = 80;
746 dark.alpha = 0;
747 dark.red = dark.green = dark.blue = 40;
749 ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
750 ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
752 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
753 ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
755 if (width > 1)
756 ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2,
757 width - cwidth - 2, height - 1, &dark);
758 ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, 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, &dark);
763 ROperateLine(img, RSubtractOperation, 0, height - 1, width - 1, height - 1, &dark);
764 #endif /* SHADOW_RESIZEBAR */
766 if (!RConvertImage(scr->rcontext, img, pmap))
767 wwarning(_("error rendering image: %s"), RMessageForError(RErrorCode));
769 RReleaseImage(img);
772 static void updateTexture(WFrameWindow * fwin)
774 int i;
775 unsigned long pixel;
777 i = fwin->flags.state;
778 if (fwin->titlebar) {
779 if (fwin->title_texture[i]->any.type != WTEX_SOLID) {
780 XSetWindowBackgroundPixmap(dpy, fwin->titlebar->window, fwin->title_back[i]);
781 if (wPreferences.new_style == TS_NEW) {
782 if (fwin->left_button && fwin->lbutton_back[i])
783 XSetWindowBackgroundPixmap(dpy, fwin->left_button->window,
784 fwin->lbutton_back[i]);
786 #ifdef XKB_BUTTON_HINT
787 if (fwin->language_button && fwin->languagebutton_back[i])
788 XSetWindowBackgroundPixmap(dpy, fwin->language_button->window,
789 fwin->languagebutton_back[i]);
790 #endif
792 if (fwin->right_button && fwin->rbutton_back[i])
793 XSetWindowBackgroundPixmap(dpy, fwin->right_button->window,
794 fwin->rbutton_back[i]);
796 } else {
797 pixel = fwin->title_texture[i]->solid.normal.pixel;
798 XSetWindowBackground(dpy, fwin->titlebar->window, pixel);
799 if (wPreferences.new_style == TS_NEW) {
800 if (fwin->left_button)
801 XSetWindowBackground(dpy, fwin->left_button->window, pixel);
802 #ifdef XKB_BUTTON_HINT
803 if (fwin->language_button)
804 XSetWindowBackground(dpy, fwin->language_button->window, pixel);
805 #endif
806 if (fwin->right_button)
807 XSetWindowBackground(dpy, fwin->right_button->window, pixel);
810 XClearWindow(dpy, fwin->titlebar->window);
812 if (fwin->left_button) {
813 XClearWindow(dpy, fwin->left_button->window);
814 handleButtonExpose(&fwin->left_button->descriptor, NULL);
816 #ifdef XKB_BUTTON_HINT
817 if (fwin->language_button) {
818 XClearWindow(dpy, fwin->language_button->window);
819 handleButtonExpose(&fwin->language_button->descriptor, NULL);
821 #endif
822 if (fwin->right_button) {
823 XClearWindow(dpy, fwin->right_button->window);
824 handleButtonExpose(&fwin->right_button->descriptor, NULL);
829 static void remakeTexture(WFrameWindow * fwin, int state)
831 Pixmap pmap, lpmap, rpmap;
832 #ifdef XKB_BUTTON_HINT
833 Pixmap tpmap;
834 #endif
836 if (fwin->title_texture[state] && fwin->titlebar) {
837 FREE_PIXMAP(fwin->title_back[state]);
838 if (wPreferences.new_style == TS_NEW) {
839 FREE_PIXMAP(fwin->lbutton_back[state]);
840 FREE_PIXMAP(fwin->rbutton_back[state]);
841 #ifdef XKB_BUTTON_HINT
842 FREE_PIXMAP(fwin->languagebutton_back[state]);
843 #endif
846 if (fwin->title_texture[state]->any.type != WTEX_SOLID) {
847 int left, right;
848 int width;
849 #ifdef XKB_BUTTON_HINT
850 int language;
851 #endif
853 /* eventually surrounded by if new_style */
854 left = fwin->left_button && !fwin->flags.hide_left_button && !fwin->flags.lbutton_dont_fit;
855 #ifdef XKB_BUTTON_HINT
856 language = fwin->language_button && !fwin->flags.hide_language_button
857 && !fwin->flags.languagebutton_dont_fit;
858 #endif
859 right = fwin->right_button && !fwin->flags.hide_right_button
860 && !fwin->flags.rbutton_dont_fit;
862 width = fwin->core->width + 1;
864 #ifdef XKB_BUTTON_HINT
865 renderTexture(fwin->screen_ptr, fwin->title_texture[state],
866 width, fwin->titlebar->height,
867 fwin->titlebar->height, fwin->titlebar->height,
868 left, language, right, &pmap, &lpmap, &tpmap, &rpmap);
869 #else
870 renderTexture(fwin->screen_ptr, fwin->title_texture[state],
871 width, fwin->titlebar->height,
872 fwin->titlebar->height, fwin->titlebar->height,
873 left, right, &pmap, &lpmap, &rpmap);
874 #endif
876 fwin->title_back[state] = pmap;
877 if (wPreferences.new_style == TS_NEW) {
878 fwin->lbutton_back[state] = lpmap;
879 fwin->rbutton_back[state] = rpmap;
880 #ifdef XKB_BUTTON_HINT
881 fwin->languagebutton_back[state] = tpmap;
882 #endif
886 if (fwin->resizebar_texture && fwin->resizebar_texture[0]
887 && fwin->resizebar && state == 0) {
889 FREE_PIXMAP(fwin->resizebar_back[0]);
891 if (fwin->resizebar_texture[0]->any.type != WTEX_SOLID) {
893 renderResizebarTexture(fwin->screen_ptr,
894 fwin->resizebar_texture[0],
895 fwin->resizebar->width,
896 fwin->resizebar->height, fwin->resizebar_corner_width, &pmap);
898 fwin->resizebar_back[0] = pmap;
901 /* this part should be in updateTexture() */
902 if (fwin->resizebar_texture[0]->any.type != WTEX_SOLID)
903 XSetWindowBackgroundPixmap(dpy, fwin->resizebar->window, fwin->resizebar_back[0]);
904 else
905 XSetWindowBackground(dpy, fwin->resizebar->window,
906 fwin->resizebar_texture[0]->solid.normal.pixel);
908 XClearWindow(dpy, fwin->resizebar->window);
912 void wFrameWindowPaint(WFrameWindow * fwin)
914 WScreen *scr = fwin->screen_ptr;
915 int state;
917 state = fwin->flags.state;
919 if (fwin->flags.is_client_window_frame)
920 fwin->flags.justification = wPreferences.title_justification;
922 if (fwin->flags.need_texture_remake) {
923 int i;
925 fwin->flags.need_texture_remake = 0;
926 fwin->flags.need_texture_change = 0;
928 if (fwin->flags.single_texture) {
929 remakeTexture(fwin, 0);
930 updateTexture(fwin);
931 } else {
932 /* first render the texture for the current state... */
933 remakeTexture(fwin, state);
934 /* ... and paint it */
935 updateTexture(fwin);
937 for (i = 0; i < 3; i++) {
938 if (i != state)
939 remakeTexture(fwin, i);
944 if (fwin->flags.need_texture_change) {
945 fwin->flags.need_texture_change = 0;
947 updateTexture(fwin);
950 if (fwin->titlebar && !fwin->flags.repaint_only_resizebar
951 && fwin->title_texture[state]->any.type == WTEX_SOLID) {
952 wDrawBevel(fwin->titlebar->window, fwin->titlebar->width,
953 fwin->titlebar->height, (WTexSolid *) fwin->title_texture[state], WREL_RAISED);
956 if (fwin->resizebar && !fwin->flags.repaint_only_titlebar
957 && fwin->resizebar_texture[0]->any.type == WTEX_SOLID) {
958 Window win;
959 int w, h;
960 int cw;
961 GC light_gc, dim_gc;
962 WTexSolid *texture = (WTexSolid *) fwin->resizebar_texture[0];
964 w = fwin->resizebar->width;
965 h = fwin->resizebar->height;
966 cw = fwin->resizebar_corner_width;
967 light_gc = texture->light_gc;
968 dim_gc = texture->dim_gc;
969 win = fwin->resizebar->window;
971 XDrawLine(dpy, win, dim_gc, 0, 0, w, 0);
972 XDrawLine(dpy, win, light_gc, 0, 1, w, 1);
974 XDrawLine(dpy, win, dim_gc, cw, 2, cw, h);
975 XDrawLine(dpy, win, light_gc, cw + 1, 2, cw + 1, h);
977 XDrawLine(dpy, win, dim_gc, w - cw - 2, 2, w - cw - 2, h);
978 XDrawLine(dpy, win, light_gc, w - cw - 1, 2, w - cw - 1, h);
980 #ifdef SHADOW_RESIZEBAR
981 XDrawLine(dpy, win, light_gc, 0, 1, 0, h - 1);
982 XDrawLine(dpy, win, dim_gc, w - 1, 2, w - 1, h - 1);
983 XDrawLine(dpy, win, dim_gc, 1, h - 1, cw, h - 1);
984 XDrawLine(dpy, win, dim_gc, cw + 2, h - 1, w - cw - 2, h - 1);
985 XDrawLine(dpy, win, dim_gc, w - cw, h - 1, w - 1, h - 1);
986 #endif /* SHADOW_RESIZEBAR */
989 if (fwin->titlebar && !fwin->flags.repaint_only_resizebar) {
990 int x, y, w, h;
991 int lofs = 6, rofs = 6;
992 int titlelen;
993 int allButtons = 1;
995 if (!wPreferences.new_style == TS_NEW) {
996 if (fwin->left_button && !fwin->flags.hide_left_button && !fwin->flags.lbutton_dont_fit)
997 lofs += fwin->left_button->width + 3;
998 else
999 allButtons = 0;
1001 #ifdef XKB_BUTTON_HINT
1002 if (fwin->language_button && !fwin->flags.hide_language_button
1003 && !fwin->flags.languagebutton_dont_fit)
1004 lofs += fwin->language_button->width;
1005 else
1006 allButtons = 0;
1007 #endif
1009 if (fwin->right_button && !fwin->flags.hide_right_button && !fwin->flags.rbutton_dont_fit)
1010 rofs += fwin->right_button->width + 3;
1011 else
1012 allButtons = 0;
1014 #ifdef XKB_BUTTON_HINT
1015 fwin->languagebutton_image = scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
1016 #endif
1018 if (fwin->title) {
1019 Drawable buf;
1020 char *title;
1022 title = ShrinkString(*fwin->font, fwin->title, fwin->titlebar->width - lofs - rofs);
1023 titlelen = strlen(title);
1024 w = WMWidthOfString(*fwin->font, title, titlelen);
1026 switch (fwin->flags.justification) {
1027 case WTJ_LEFT:
1028 x = lofs;
1029 break;
1031 case WTJ_RIGHT:
1032 x = fwin->titlebar->width - w - rofs;
1033 break;
1035 default:
1036 if (!allButtons)
1037 x = lofs + (fwin->titlebar->width - w - lofs - rofs) / 2;
1038 else
1039 x = (fwin->titlebar->width - w) / 2;
1040 break;
1043 y = *fwin->title_clearance + TITLEBAR_EXTEND_SPACE;
1044 h = WMFontHeight(*fwin->font);
1046 if (y*2 + h > *fwin->title_max_height)
1047 y = (*fwin->title_max_height - h) / 2;
1049 if (y*2 + h < *fwin->title_min_height)
1050 y = (*fwin->title_min_height - h) / 2;
1052 /* We use a w+2 buffer to have an extra pixel on the left and
1053 * another one on the right. This is because for some odd reason,
1054 * sometimes when using AA fonts (when libfreetype2 is compiled
1055 * with bytecode interpreter turned off), some fonts are drawn
1056 * starting from x = -1 not from 0 as requested. Observed with
1057 * capital A letter on the bold 'trebuchet ms' font. -Dan
1059 buf = XCreatePixmap(dpy, fwin->titlebar->window, w + 2, h, scr->w_depth);
1061 XSetClipMask(dpy, scr->copy_gc, None);
1063 if (fwin->title_texture[state]->any.type != WTEX_SOLID) {
1064 XCopyArea(dpy, fwin->title_back[state], buf, scr->copy_gc,
1065 x - 1, y, w + 2, h, 0, 0);
1066 } else {
1067 XSetForeground(dpy, scr->copy_gc, fwin->title_texture[state]->solid.normal.pixel);
1068 XFillRectangle(dpy, buf, scr->copy_gc, 0, 0, w + 2, h);
1071 /*XDrawRectangle(dpy, buf, WMColorGC(scr->white),1,0,w,h-1); */
1072 WMDrawString(scr->wmscreen, buf, fwin->title_color[state],
1073 *fwin->font, 1, 0, title, titlelen);
1075 XCopyArea(dpy, buf, fwin->titlebar->window, scr->copy_gc, 0, 0, w + 2, h, x - 1, y);
1077 XFreePixmap(dpy, buf);
1079 wfree(title);
1082 if (fwin->left_button)
1083 handleButtonExpose(&fwin->left_button->descriptor, NULL);
1084 if (fwin->right_button)
1085 handleButtonExpose(&fwin->right_button->descriptor, NULL);
1086 #ifdef XKB_BUTTON_HINT
1087 if (fwin->language_button)
1088 handleButtonExpose(&fwin->language_button->descriptor, NULL);
1089 #endif
1093 static void reconfigure(WFrameWindow * fwin, int x, int y, int width, int height, Bool dontMove)
1095 int k = (wPreferences.new_style == TS_NEW ? 4 : 3);
1096 int resizedHorizontally = 0;
1098 if (dontMove)
1099 XResizeWindow(dpy, fwin->core->window, width, height);
1100 else
1101 XMoveResizeWindow(dpy, fwin->core->window, x, y, width, height);
1103 if (fwin->core->width != width) {
1104 fwin->flags.need_texture_remake = 1;
1105 resizedHorizontally = 1;
1108 fwin->core->width = width;
1109 fwin->core->height = height;
1111 if (fwin->titlebar && resizedHorizontally) {
1112 /* Check if the titlebar is wide enough to hold the buttons.
1113 * Temporarily remove them if can't
1115 if (fwin->left_button) {
1116 if (width < fwin->top_width * k && !fwin->flags.lbutton_dont_fit) {
1117 if (!fwin->flags.hide_left_button)
1118 XUnmapWindow(dpy, fwin->left_button->window);
1120 fwin->flags.lbutton_dont_fit = 1;
1121 } else if (width >= fwin->top_width * k && fwin->flags.lbutton_dont_fit) {
1122 if (!fwin->flags.hide_left_button)
1123 XMapWindow(dpy, fwin->left_button->window);
1125 fwin->flags.lbutton_dont_fit = 0;
1128 #ifdef XKB_BUTTON_HINT
1129 if (fwin->language_button) {
1130 if (width < fwin->top_width * k && !fwin->flags.languagebutton_dont_fit) {
1131 if (!fwin->flags.hide_language_button)
1132 XUnmapWindow(dpy, fwin->language_button->window);
1134 fwin->flags.languagebutton_dont_fit = 1;
1135 } else if (width >= fwin->top_width * k && fwin->flags.languagebutton_dont_fit) {
1136 if (!fwin->flags.hide_language_button)
1137 XMapWindow(dpy, fwin->language_button->window);
1139 fwin->flags.languagebutton_dont_fit = 0;
1142 #endif
1144 if (fwin->right_button) {
1145 if (width < fwin->top_width * 2 && !fwin->flags.rbutton_dont_fit) {
1146 if (!fwin->flags.hide_right_button)
1147 XUnmapWindow(dpy, fwin->right_button->window);
1149 fwin->flags.rbutton_dont_fit = 1;
1150 } else if (width >= fwin->top_width * 2 && fwin->flags.rbutton_dont_fit) {
1151 if (!fwin->flags.hide_right_button)
1152 XMapWindow(dpy, fwin->right_button->window);
1154 fwin->flags.rbutton_dont_fit = 0;
1158 if (wPreferences.new_style == TS_NEW) {
1159 if (fwin->right_button)
1160 XMoveWindow(dpy, fwin->right_button->window,
1161 width - fwin->right_button->width + 1, 0);
1162 } else {
1163 if (fwin->right_button)
1164 XMoveWindow(dpy, fwin->right_button->window,
1165 width - fwin->right_button->width - 3,
1166 (fwin->titlebar->height - fwin->right_button->height) / 2);
1168 updateTitlebar(fwin);
1169 checkTitleSize(fwin);
1172 if (fwin->resizebar) {
1173 wCoreConfigure(fwin->resizebar, 0,
1174 fwin->core->height - fwin->resizebar->height,
1175 fwin->core->width, fwin->resizebar->height);
1177 fwin->resizebar_corner_width = RESIZEBAR_CORNER_WIDTH;
1178 if (fwin->core->width < RESIZEBAR_CORNER_WIDTH * 2 + RESIZEBAR_MIN_WIDTH)
1179 fwin->resizebar_corner_width = fwin->core->width / 2;
1183 void wFrameWindowConfigure(WFrameWindow * fwin, int x, int y, int width, int height)
1185 reconfigure(fwin, x, y, width, height, False);
1188 void wFrameWindowResize(WFrameWindow * fwin, int width, int height)
1190 reconfigure(fwin, 0, 0, width, height, True);
1193 int wFrameWindowChangeTitle(WFrameWindow *fwin, const char *new_title)
1195 /* check if the title is the same as before */
1196 if (fwin->title) {
1197 if (new_title && (strcmp(fwin->title, new_title) == 0))
1198 return 0;
1199 } else {
1200 if (!new_title)
1201 return 0;
1204 if (fwin->title)
1205 wfree(fwin->title);
1207 fwin->title = wstrdup(new_title);
1209 if (fwin->titlebar) {
1210 XClearWindow(dpy, fwin->titlebar->window);
1212 wFrameWindowPaint(fwin);
1214 checkTitleSize(fwin);
1216 return 1;
1219 #ifdef XKB_BUTTON_HINT
1220 void wFrameWindowUpdateLanguageButton(WFrameWindow * fwin)
1222 paintButton(fwin->language_button, fwin->title_texture[fwin->flags.state],
1223 WMColorPixel(fwin->title_color[fwin->flags.state]), fwin->languagebutton_image, True);
1225 #endif /* XKB_BUTTON_HINT */
1227 /*********************************************************************/
1229 static void handleExpose(WObjDescriptor * desc, XEvent * event)
1231 WFrameWindow *fwin = (WFrameWindow *) desc->parent;
1233 if (fwin->titlebar && fwin->titlebar->window == event->xexpose.window)
1234 fwin->flags.repaint_only_titlebar = 1;
1235 if (fwin->resizebar && fwin->resizebar->window == event->xexpose.window)
1236 fwin->flags.repaint_only_resizebar = 1;
1237 wFrameWindowPaint(fwin);
1238 fwin->flags.repaint_only_titlebar = 0;
1239 fwin->flags.repaint_only_resizebar = 0;
1242 static void checkTitleSize(WFrameWindow * fwin)
1244 int width;
1246 if (!fwin->title) {
1247 fwin->flags.incomplete_title = 0;
1248 return;
1251 if (!fwin->titlebar) {
1252 fwin->flags.incomplete_title = 1;
1253 return;
1254 } else {
1255 width = fwin->titlebar->width - 6 - 6;
1258 if (!wPreferences.new_style == TS_NEW) {
1259 if (fwin->left_button && !fwin->flags.hide_left_button && !fwin->flags.lbutton_dont_fit)
1260 width -= fwin->left_button->width + 3;
1262 #ifdef XKB_BUTTON_HINT
1263 if (fwin->language_button && !fwin->flags.hide_language_button
1264 && !fwin->flags.languagebutton_dont_fit)
1265 width -= fwin->language_button->width + 3;
1266 #endif
1268 if (fwin->right_button && !fwin->flags.hide_right_button && !fwin->flags.rbutton_dont_fit)
1269 width -= fwin->right_button->width + 3;
1272 if (WMWidthOfString(*fwin->font, fwin->title, strlen(fwin->title)) > width)
1273 fwin->flags.incomplete_title = 1;
1274 else
1275 fwin->flags.incomplete_title = 0;
1278 static void paintButton(WCoreWindow * button, WTexture * texture, unsigned long color, WPixmap * image, int pushed)
1280 WScreen *scr = button->screen_ptr;
1281 GC copy_gc = scr->copy_gc;
1282 int x = 0, y = 0, d = 0;
1283 int left = 0, width = 0;
1285 /* setup stuff according to the state */
1286 if (pushed) {
1287 if (image) {
1288 if (image->width >= image->height * 2) {
1289 /* the image contains 2 pictures: the second is for the
1290 * pushed state */
1291 width = image->width / 2;
1292 left = image->width / 2;
1293 } else {
1294 width = image->width;
1297 XSetClipMask(dpy, copy_gc, None);
1298 if (wPreferences.new_style == TS_NEXT)
1299 XSetForeground(dpy, copy_gc, scr->black_pixel);
1300 else
1301 XSetForeground(dpy, copy_gc, scr->white_pixel);
1303 d = 1;
1304 if (wPreferences.new_style == TS_NEW) {
1305 XFillRectangle(dpy, button->window, copy_gc, 0, 0, button->width - 1, button->height - 1);
1306 XSetForeground(dpy, copy_gc, scr->black_pixel);
1307 XDrawRectangle(dpy, button->window, copy_gc, 0, 0, button->width - 1, button->height - 1);
1308 } else if (wPreferences.new_style == TS_OLD) {
1309 XFillRectangle(dpy, button->window, copy_gc, 0, 0, button->width, button->height);
1310 XSetForeground(dpy, copy_gc, scr->black_pixel);
1311 XDrawRectangle(dpy, button->window, copy_gc, 0, 0, button->width, button->height);
1312 } else {
1313 XFillRectangle(dpy, button->window, copy_gc, 0, 0, button->width-3, button->height-3);
1314 XSetForeground(dpy, copy_gc, scr->black_pixel);
1315 XDrawRectangle(dpy, button->window, copy_gc, 0, 0, button->width-3, button->height-3);
1317 } else {
1318 XClearWindow(dpy, button->window);
1320 if (image) {
1321 if (image->width >= image->height * 2)
1322 width = image->width / 2;
1323 else
1324 width = image->width;
1326 d = 0;
1328 if (wPreferences.new_style == TS_NEW) {
1329 if (texture->any.type == WTEX_SOLID || pushed)
1330 wDrawBevel(button->window, button->width, button->height,
1331 (WTexSolid *) texture, WREL_RAISED);
1332 } else {
1333 wDrawBevel(button->window, button->width, button->height,
1334 scr->widget_texture, WREL_RAISED);
1338 if (image) {
1339 /* display image */
1340 XSetClipMask(dpy, copy_gc, image->mask);
1341 x = (button->width - width) / 2 + d;
1342 y = (button->height - image->height) / 2 + d;
1343 XSetClipOrigin(dpy, copy_gc, x - left, y);
1344 if (!wPreferences.new_style == TS_NEW) {
1345 XSetForeground(dpy, copy_gc, scr->black_pixel);
1346 if (!pushed) {
1347 if (image->depth == 1)
1348 XCopyPlane(dpy, image->image, button->window, copy_gc,
1349 left, 0, width, image->height, x, y, 1);
1350 else
1351 XCopyArea(dpy, image->image, button->window, copy_gc,
1352 left, 0, width, image->height, x, y);
1353 } else {
1354 if (wPreferences.new_style == TS_OLD) {
1355 XSetForeground(dpy, copy_gc, scr->dark_pixel);
1356 XFillRectangle(dpy, button->window, copy_gc, 0, 0,
1357 button->width, button->height);
1358 } else {
1359 XSetForeground(dpy, copy_gc, scr->black_pixel);
1360 XCopyArea(dpy, image->image, button->window, copy_gc,
1361 left, 0, width, image->height, x, y);
1364 } else {
1365 if (pushed) {
1366 XSetForeground(dpy, copy_gc, scr->black_pixel);
1367 } else {
1368 XSetForeground(dpy, copy_gc, color);
1369 XSetBackground(dpy, copy_gc, texture->any.color.pixel);
1371 XFillRectangle(dpy, button->window, copy_gc, 0, 0, button->width, button->height);
1376 static void handleButtonExpose(WObjDescriptor * desc, XEvent * event)
1378 WFrameWindow *fwin = (WFrameWindow *) desc->parent;
1379 WCoreWindow *button = (WCoreWindow *) desc->self;
1381 #ifdef XKB_BUTTON_HINT
1382 if (button == fwin->language_button) {
1383 if (wPreferences.modelock)
1384 paintButton(button, fwin->title_texture[fwin->flags.state],
1385 WMColorPixel(fwin->title_color[fwin->flags.state]),
1386 fwin->languagebutton_image, False);
1387 } else
1388 #endif
1389 if (button == fwin->left_button)
1390 paintButton(button, fwin->title_texture[fwin->flags.state],
1391 WMColorPixel(fwin->title_color[fwin->flags.state]), fwin->lbutton_image, False);
1392 else
1393 paintButton(button, fwin->title_texture[fwin->flags.state],
1394 WMColorPixel(fwin->title_color[fwin->flags.state]), fwin->rbutton_image, False);
1397 static void titlebarMouseDown(WObjDescriptor * desc, XEvent * event)
1399 WFrameWindow *fwin = desc->parent;
1400 WCoreWindow *titlebar = desc->self;
1402 if (IsDoubleClick(fwin->core->screen_ptr, event)) {
1403 if (fwin->on_dblclick_titlebar)
1404 (*fwin->on_dblclick_titlebar) (titlebar, fwin->child, event);
1405 } else {
1406 if (fwin->on_mousedown_titlebar)
1407 (*fwin->on_mousedown_titlebar) (titlebar, fwin->child, event);
1411 static void resizebarMouseDown(WObjDescriptor * desc, XEvent * event)
1413 WFrameWindow *fwin = desc->parent;
1414 WCoreWindow *resizebar = desc->self;
1416 if (fwin->on_mousedown_resizebar)
1417 (*fwin->on_mousedown_resizebar) (resizebar, fwin->child, event);
1420 static void buttonMouseDown(WObjDescriptor * desc, XEvent * event)
1422 WFrameWindow *fwin = desc->parent;
1423 WCoreWindow *button = desc->self;
1424 WPixmap *image;
1425 XEvent ev;
1426 int done = 0, execute = 1;
1427 WTexture *texture;
1428 unsigned long pixel;
1429 int clickButton = event->xbutton.button;
1431 if (IsDoubleClick(fwin->core->screen_ptr, event)) {
1432 if (button == fwin->right_button && fwin->on_dblclick_right)
1433 (*fwin->on_dblclick_right) (button, fwin->child, event);
1435 return;
1438 if (button == fwin->left_button)
1439 image = fwin->lbutton_image;
1440 else
1441 image = fwin->rbutton_image;
1443 #ifdef XKB_BUTTON_HINT
1444 if (button == fwin->language_button) {
1445 if (!wPreferences.modelock)
1446 return;
1447 image = fwin->languagebutton_image;
1449 #endif
1451 pixel = WMColorPixel(fwin->title_color[fwin->flags.state]);
1452 texture = fwin->title_texture[fwin->flags.state];
1453 paintButton(button, texture, pixel, image, True);
1455 while (!done) {
1456 WMMaskEvent(dpy, LeaveWindowMask | EnterWindowMask | ButtonReleaseMask
1457 | ButtonPressMask | ExposureMask, &ev);
1458 switch (ev.type) {
1459 case LeaveNotify:
1460 execute = 0;
1461 paintButton(button, texture, pixel, image, False);
1462 break;
1464 case EnterNotify:
1465 execute = 1;
1466 paintButton(button, texture, pixel, image, True);
1467 break;
1469 case ButtonPress:
1470 break;
1472 case ButtonRelease:
1473 if (ev.xbutton.button == clickButton)
1474 done = 1;
1475 break;
1477 default:
1478 WMHandleEvent(&ev);
1481 paintButton(button, texture, pixel, image, False);
1483 if (execute) {
1484 if (button == fwin->left_button) {
1485 if (fwin->on_click_left)
1486 (*fwin->on_click_left) (button, fwin->child, &ev);
1487 } else if (button == fwin->right_button) {
1488 if (fwin->on_click_right)
1489 (*fwin->on_click_right) (button, fwin->child, &ev);
1491 #ifdef XKB_BUTTON_HINT
1492 else if (button == fwin->language_button) {
1493 if (fwin->on_click_language)
1494 (*fwin->on_click_language) (button, fwin->child, &ev);
1496 #endif