Change to the linux kernel coding style
[wmaker-crm.git] / src / framewin.c
Commit [+]AuthorDateLineData
6830b057 dan2004-10-12 21:28:27 +00001/*
9af1c6c4 dan1998-10-21 14:43:47 +00002 * Window Maker window manager
6830b057 dan2004-10-12 21:28:27 +00003 *
4153e2fd dan2003-01-16 23:30:45 +00004 * Copyright (c) 1997-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00005 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00006 * 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.
10 *
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.
15 *
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
6830b057 dan2004-10-12 21:28:27 +000018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000019 * USA.
20 */
21
22#include "wconfig.h"
23
24#include <X11/Xlib.h>
25#include <X11/Xutil.h>
6830b057 dan2004-10-12 21:28:27 +000026#ifdef KEEP_XKB_LOCK_STATUS
27#include <X11/XKBlib.h>
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020028#endif /* KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +000029
30#include <stdlib.h>
31#include <string.h>
32
33#include <wraster.h>
34
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"
43
44#define DBLCLICK_TIME wPreferences.dblclick_time
45
46extern WPreferences wPreferences;
47
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020048static void handleExpose(WObjDescriptor * desc, XEvent * event);
49static void handleButtonExpose(WObjDescriptor * desc, XEvent * event);
9d2e6ef9 scottc1998-09-29 22:36:29 +000050
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020051static void buttonMouseDown(WObjDescriptor * desc, XEvent * event);
52static void titlebarMouseDown(WObjDescriptor * desc, XEvent * event);
53static void resizebarMouseDown(WObjDescriptor * desc, XEvent * event);
9d2e6ef9 scottc1998-09-29 22:36:29 +000054
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020055static void checkTitleSize(WFrameWindow * fwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +000056
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020057static void paintButton(WCoreWindow * button, WTexture * texture,
58 unsigned long color, WPixmap * image, int pushed);
9d2e6ef9 scottc1998-09-29 22:36:29 +000059
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020060static void updateTitlebar(WFrameWindow * fwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +000061
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020062WFrameWindow *wFrameWindowCreate(WScreen * scr, int wlevel, int x, int y,
63 int width, int height, int *clearance, int flags,
64 WTexture ** title_texture, WTexture ** resize_texture,
65 WMColor ** color, WMFont ** font)
9d2e6ef9 scottc1998-09-29 22:36:29 +000066{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020067 WFrameWindow *fwin;
6830b057 dan2004-10-12 21:28:27 +000068
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020069 fwin = wmalloc(sizeof(WFrameWindow));
70 memset(fwin, 0, sizeof(WFrameWindow));
6830b057 dan2004-10-12 21:28:27 +000071
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020072 fwin->screen_ptr = scr;
9d2e6ef9 scottc1998-09-29 22:36:29 +000073
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020074 fwin->flags.single_texture = (flags & WFF_SINGLE_STATE) ? 1 : 0;
6830b057 dan2004-10-12 21:28:27 +000075
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020076 fwin->title_texture = title_texture;
77 fwin->resizebar_texture = resize_texture;
78 fwin->title_color = color;
79 fwin->title_clearance = clearance;
80 fwin->font = font;
54927f00 kojima1999-05-30 05:10:54 +000081#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020082 fwin->languagemode = XkbGroup1Index;
83 fwin->last_languagemode = XkbGroup2Index;
54927f00 kojima1999-05-30 05:10:54 +000084#endif
f2de1c9d kojima2000-01-14 16:30:56 +000085
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020086 fwin->core = wCoreCreateTopLevel(scr, x, y, width, height, (flags & WFF_BORDER)
87 ? FRAME_BORDER_WIDTH : 0);
88 if (wPreferences.use_saveunders) {
89 unsigned long vmask;
90 XSetWindowAttributes attribs;
6830b057 dan2004-10-12 21:28:27 +000091
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020092 vmask = CWSaveUnder;
93 attribs.save_under = True;
94 XChangeWindowAttributes(dpy, fwin->core->window, vmask, &attribs);
95 }
6830b057 dan2004-10-12 21:28:27 +000096
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020097 /* setup stacking information */
98 fwin->core->stacking = wmalloc(sizeof(WStacking));
99 fwin->core->stacking->above = NULL;
100 fwin->core->stacking->under = NULL;
101 fwin->core->stacking->child_of = NULL;
102 fwin->core->stacking->window_level = wlevel;
6830b057 dan2004-10-12 21:28:27 +0000103
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200104 AddToStackList(fwin->core);
6830b057 dan2004-10-12 21:28:27 +0000105
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200106 wFrameWindowUpdateBorders(fwin, flags);
6830b057 dan2004-10-12 21:28:27 +0000107
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200108 return fwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000109}
110
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200111void wFrameWindowUpdateBorders(WFrameWindow * fwin, int flags)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000112{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200113 int theight;
114 int bsize;
115 int width, height;
116 int i;
117 WScreen *scr = fwin->screen_ptr;
118
119 width = fwin->core->width;
120 if (flags & WFF_IS_SHADED)
121 height = -1;
122 else
123 height = fwin->core->height - fwin->top_width - fwin->bottom_width;
124
125 if (flags & WFF_TITLEBAR)
126 theight = WMFontHeight(*fwin->font) + (*fwin->title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
127 else
128 theight = 0;
129
130 if (wPreferences.new_style) {
131 bsize = theight;
132 } else {
133 bsize = theight - 7;
134 }
135
136 if (fwin->titlebar) {
137 /* if we had a titlebar and is requesting for one,
138 * check if the size has changed and resize it */
139 if (flags & WFF_TITLEBAR) {
140 fwin->top_width = theight;
141
142 fwin->flags.need_texture_remake = 1;
143
144 if (wPreferences.new_style) {
145 if (fwin->left_button) {
146 wCoreConfigure(fwin->left_button, 0, 0, bsize, bsize);
147 }
54927f00 kojima1999-05-30 05:10:54 +0000148#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200149 if (fwin->language_button)
150 if (fwin->flags.hide_left_button || !fwin->left_button
151 || fwin->flags.lbutton_dont_fit) {
152 wCoreConfigure(fwin->language_button, 0, 0, bsize, bsize);
153 } else {
154 wCoreConfigure(fwin->language_button, bsize, 0, bsize, bsize);
155 }
54927f00 kojima1999-05-30 05:10:54 +0000156#endif
157
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200158 if (fwin->right_button) {
159 wCoreConfigure(fwin->right_button, width - bsize + 1, 0, bsize, bsize);
160 }
161 } else { /* !new_style */
162 if (fwin->left_button) {
163 wCoreConfigure(fwin->left_button, 3, (theight - bsize) / 2, bsize, bsize);
164 }
54927f00 kojima1999-05-30 05:10:54 +0000165#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200166 if (fwin->language_button) {
167 wCoreConfigure(fwin->language_button, 6 + bsize, (theight - bsize) / 2,
168 bsize, bsize);
169 }
54927f00 kojima1999-05-30 05:10:54 +0000170#endif
6830b057 dan2004-10-12 21:28:27 +0000171
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200172 if (fwin->right_button) {
173 wCoreConfigure(fwin->right_button, width - bsize - 3,
174 (theight - bsize) / 2, bsize, bsize);
175 }
176 }
177 updateTitlebar(fwin);
178 } else {
179 /* we had a titlebar, but now we don't need it anymore */
180 for (i = 0; i < (fwin->flags.single_texture ? 1 : 3); i++) {
181 FREE_PIXMAP(fwin->title_back[i]);
182 if (wPreferences.new_style) {
183 FREE_PIXMAP(fwin->lbutton_back[i]);
184 FREE_PIXMAP(fwin->rbutton_back[i]);
54927f00 kojima1999-05-30 05:10:54 +0000185#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200186 FREE_PIXMAP(fwin->languagebutton_back[i]);
54927f00 kojima1999-05-30 05:10:54 +0000187#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200188 }
189 }
190 if (fwin->left_button)
191 wCoreDestroy(fwin->left_button);
192 fwin->left_button = NULL;
6830b057 dan2004-10-12 21:28:27 +0000193
54927f00 kojima1999-05-30 05:10:54 +0000194#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200195 if (fwin->language_button)
196 wCoreDestroy(fwin->language_button);
197 fwin->language_button = NULL;
54927f00 kojima1999-05-30 05:10:54 +0000198#endif
199
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200200 if (fwin->right_button)
201 wCoreDestroy(fwin->right_button);
202 fwin->right_button = NULL;
203
204 wCoreDestroy(fwin->titlebar);
205 fwin->titlebar = NULL;
206
207 fwin->top_width = 0;
208 }
209 } else {
210 /* if we didn't have a titlebar and are being requested for
211 * one, create it */
212 if (flags & WFF_TITLEBAR) {
213 fwin->top_width = theight;
214
215 fwin->flags.titlebar = 1;
216 fwin->titlebar = wCoreCreate(fwin->core, 0, 0, width + 1, theight);
217
218 if (flags & WFF_LEFT_BUTTON) {
219 fwin->flags.left_button = 1;
220 if (wPreferences.new_style) {
221 fwin->left_button = wCoreCreate(fwin->core, 0, 0, bsize, bsize);
222 if (width < theight * 4) {
223 fwin->flags.lbutton_dont_fit = 1;
224 } else {
225 XMapRaised(dpy, fwin->left_button->window);
226 }
227 } else {
228 fwin->left_button =
229 wCoreCreate(fwin->titlebar, 3, (theight - bsize) / 2, bsize, bsize);
230
231 XSetWindowBackground(dpy, fwin->left_button->window,
232 scr->widget_texture->normal.pixel);
233
234 if (width < theight * 3) {
235 fwin->flags.lbutton_dont_fit = 1;
236 } else {
237 XMapRaised(dpy, fwin->left_button->window);
238 }
239 }
240 }
54927f00 kojima1999-05-30 05:10:54 +0000241#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200242 if (flags & WFF_LANGUAGE_BUTTON) {
243 fwin->flags.language_button = 1;
244 if (wPreferences.new_style) {
245 fwin->language_button = wCoreCreate(fwin->core, bsize, 0, bsize, bsize);
246
247 if (width < theight * 4) {
248 fwin->flags.languagebutton_dont_fit = 1;
249 } else {
250 XMapRaised(dpy, fwin->language_button->window);
251 }
252 } else {
253 fwin->language_button =
254 wCoreCreate(fwin->titlebar, bsize + 6, (theight - bsize) / 2,
255 bsize, bsize);
256
257 XSetWindowBackground(dpy, fwin->language_button->window,
258 scr->widget_texture->normal.pixel);
259
260 if (width < theight * 3) {
261 fwin->flags.languagebutton_dont_fit = 1;
262 } else {
263 XMapRaised(dpy, fwin->language_button->window);
264 }
265 }
266 }
54927f00 kojima1999-05-30 05:10:54 +0000267#endif
6830b057 dan2004-10-12 21:28:27 +0000268
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200269 if (flags & WFF_RIGHT_BUTTON) {
270 fwin->flags.right_button = 1;
271 if (wPreferences.new_style) {
272 fwin->right_button =
273 wCoreCreate(fwin->core, width - bsize + 1, 0, bsize, bsize);
274 } else {
275 fwin->right_button =
276 wCoreCreate(fwin->titlebar, width - bsize - 3,
277 (theight - bsize) / 2, bsize, bsize);
278 XSetWindowBackground(dpy, fwin->right_button->window,
279 scr->widget_texture->normal.pixel);
280 }
281
282 if (width < theight * 2) {
283 fwin->flags.rbutton_dont_fit = 1;
284 } else {
285 XMapRaised(dpy, fwin->right_button->window);
286 }
287 }
288
289 if (wPreferences.new_style)
290 updateTitlebar(fwin);
291
292 XMapRaised(dpy, fwin->titlebar->window);
293
294 fwin->flags.need_texture_remake = 1;
295 }
296 }
297 checkTitleSize(fwin);
298
299 if (flags & WFF_RESIZEBAR) {
300 fwin->bottom_width = RESIZEBAR_HEIGHT;
301
302 if (!fwin->resizebar) {
303 fwin->flags.resizebar = 1;
304 fwin->resizebar = wCoreCreate(fwin->core, 0,
305 height + fwin->top_width, width, RESIZEBAR_HEIGHT);
306 fwin->resizebar_corner_width = RESIZEBAR_CORNER_WIDTH;
307 if (width < RESIZEBAR_CORNER_WIDTH * 2 + RESIZEBAR_MIN_WIDTH) {
308 fwin->resizebar_corner_width = (width - RESIZEBAR_MIN_WIDTH) / 2;
309 if (fwin->resizebar_corner_width < 0)
310 fwin->resizebar_corner_width = 0;
311 }
312
313 XMapWindow(dpy, fwin->resizebar->window);
314 XLowerWindow(dpy, fwin->resizebar->window);
315
316 fwin->flags.need_texture_remake = 1;
317 } else {
318 if (height + fwin->top_width + fwin->bottom_width != fwin->core->height) {
319 wCoreConfigure(fwin->resizebar, 0, height + fwin->top_width,
320 width, RESIZEBAR_HEIGHT);
321 }
322 }
323 } else {
324 fwin->bottom_width = 0;
325
326 if (fwin->resizebar) {
327 fwin->bottom_width = 0;
328 wCoreDestroy(fwin->resizebar);
329 fwin->resizebar = NULL;
330 }
331 }
332
333 if (height + fwin->top_width + fwin->bottom_width != fwin->core->height && !(flags & WFF_IS_SHADED)) {
334 wFrameWindowResize(fwin, width, height + fwin->top_width + fwin->bottom_width);
335 }
336
337 if (flags & WFF_BORDER) {
338 XSetWindowBorderWidth(dpy, fwin->core->window, FRAME_BORDER_WIDTH);
339 } else {
340 XSetWindowBorderWidth(dpy, fwin->core->window, 0);
341 }
342
343 /* setup object descriptors */
344
345 if (fwin->titlebar) {
346 fwin->titlebar->descriptor.handle_expose = handleExpose;
347 fwin->titlebar->descriptor.parent = fwin;
348 fwin->titlebar->descriptor.parent_type = WCLASS_FRAME;
349 fwin->titlebar->descriptor.handle_mousedown = titlebarMouseDown;
350 }
351
352 if (fwin->resizebar) {
353 fwin->resizebar->descriptor.handle_expose = handleExpose;
354 fwin->resizebar->descriptor.parent = fwin;
355 fwin->resizebar->descriptor.parent_type = WCLASS_FRAME;
356 fwin->resizebar->descriptor.handle_mousedown = resizebarMouseDown;
357 }
358
359 if (fwin->left_button) {
360 fwin->left_button->descriptor.handle_expose = handleButtonExpose;
361 fwin->left_button->descriptor.parent = fwin;
362 fwin->left_button->descriptor.parent_type = WCLASS_FRAME;
363 fwin->left_button->descriptor.handle_mousedown = buttonMouseDown;
364 }
54927f00 kojima1999-05-30 05:10:54 +0000365#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200366 if (fwin->language_button) {
367 fwin->language_button->descriptor.handle_expose = handleButtonExpose;
368 fwin->language_button->descriptor.parent = fwin;
369 fwin->language_button->descriptor.parent_type = WCLASS_FRAME;
370 fwin->language_button->descriptor.handle_mousedown = buttonMouseDown;
371 }
54927f00 kojima1999-05-30 05:10:54 +0000372#endif
373
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200374 if (fwin->right_button) {
375 fwin->right_button->descriptor.parent = fwin;
376 fwin->right_button->descriptor.parent_type = WCLASS_FRAME;
377 fwin->right_button->descriptor.handle_expose = handleButtonExpose;
378 fwin->right_button->descriptor.handle_mousedown = buttonMouseDown;
379 }
6830b057 dan2004-10-12 21:28:27 +0000380
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200381 checkTitleSize(fwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000382}
383
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200384void wFrameWindowDestroy(WFrameWindow * fwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000385{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200386 int i;
6830b057 dan2004-10-12 21:28:27 +0000387
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200388 if (fwin->left_button)
389 wCoreDestroy(fwin->left_button);
6830b057 dan2004-10-12 21:28:27 +0000390
54927f00 kojima1999-05-30 05:10:54 +0000391#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200392 if (fwin->language_button)
393 wCoreDestroy(fwin->language_button);
54927f00 kojima1999-05-30 05:10:54 +0000394#endif
6830b057 dan2004-10-12 21:28:27 +0000395
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200396 if (fwin->right_button)
397 wCoreDestroy(fwin->right_button);
6830b057 dan2004-10-12 21:28:27 +0000398
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200399 if (fwin->resizebar)
400 wCoreDestroy(fwin->resizebar);
6830b057 dan2004-10-12 21:28:27 +0000401
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200402 if (fwin->titlebar)
403 wCoreDestroy(fwin->titlebar);
6830b057 dan2004-10-12 21:28:27 +0000404
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200405 RemoveFromStackList(fwin->core);
6830b057 dan2004-10-12 21:28:27 +0000406
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200407 wCoreDestroy(fwin->core);
6830b057 dan2004-10-12 21:28:27 +0000408
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200409 if (fwin->title)
410 wfree(fwin->title);
6830b057 dan2004-10-12 21:28:27 +0000411
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200412 for (i = 0; i < (fwin->flags.single_texture ? 1 : 3); i++) {
413 FREE_PIXMAP(fwin->title_back[i]);
414 if (wPreferences.new_style) {
415 FREE_PIXMAP(fwin->lbutton_back[i]);
54927f00 kojima1999-05-30 05:10:54 +0000416#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200417 FREE_PIXMAP(fwin->languagebutton_back[i]);
54927f00 kojima1999-05-30 05:10:54 +0000418#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200419 FREE_PIXMAP(fwin->rbutton_back[i]);
420 }
421 }
6830b057 dan2004-10-12 21:28:27 +0000422
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200423 wfree(fwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000424}
425
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200426void wFrameWindowChangeState(WFrameWindow * fwin, int state)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000427{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200428 if (fwin->flags.state == state)
429 return;
6830b057 dan2004-10-12 21:28:27 +0000430
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200431 fwin->flags.state = state;
432 fwin->flags.need_texture_change = 1;
6830b057 dan2004-10-12 21:28:27 +0000433
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200434 wFrameWindowPaint(fwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000435}
436
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200437static void updateTitlebar(WFrameWindow * fwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000438{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200439 int x, w;
440 int theight;
6830b057 dan2004-10-12 21:28:27 +0000441
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200442 theight = WMFontHeight(*fwin->font) + (*fwin->title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000443
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200444 x = 0;
445 w = fwin->core->width + 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000446
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200447 if (wPreferences.new_style) {
448 if (fwin->flags.hide_left_button || !fwin->left_button || fwin->flags.lbutton_dont_fit) {
449 x = 0;
54927f00 kojima1999-05-30 05:10:54 +0000450#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200451 if (fwin->language_button)
452 wCoreConfigure(fwin->language_button, 0, 0,
453 fwin->language_button->width, fwin->language_button->width);
54927f00 kojima1999-05-30 05:10:54 +0000454#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200455 } else {
54927f00 kojima1999-05-30 05:10:54 +0000456#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200457 if (fwin->language_button)
458 wCoreConfigure(fwin->language_button, fwin->left_button->width, 0,
459 fwin->language_button->width, fwin->language_button->width);
54927f00 kojima1999-05-30 05:10:54 +0000460#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200461 x = fwin->left_button->width;
462 w -= fwin->left_button->width;
463 }
54927f00 kojima1999-05-30 05:10:54 +0000464#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200465 if (fwin->flags.hide_language_button || !fwin->language_button
466 || fwin->flags.languagebutton_dont_fit) {
467 } else {
468 x += fwin->language_button->width;
469 w -= fwin->language_button->width;
470 }
54927f00 kojima1999-05-30 05:10:54 +0000471#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200472 }
54927f00 kojima1999-05-30 05:10:54 +0000473#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200474 else {
475 int bsize = theight - 7;
476 if (fwin->flags.hide_left_button || !fwin->left_button || fwin->flags.lbutton_dont_fit) {
477 if (fwin->language_button)
478 wCoreConfigure(fwin->language_button, 3, (theight - bsize) / 2,
479 fwin->language_button->width, fwin->language_button->width);
480 } else {
481 if (fwin->language_button)
482 wCoreConfigure(fwin->language_button,
483 6 + fwin->left_button->width, (theight - bsize) / 2,
484 fwin->language_button->width, fwin->language_button->width);
485 }
486 }
54927f00 kojima1999-05-30 05:10:54 +0000487#endif
6830b057 dan2004-10-12 21:28:27 +0000488
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200489 if (wPreferences.new_style) {
490 if (!fwin->flags.hide_right_button && fwin->right_button && !fwin->flags.rbutton_dont_fit) {
491 w -= fwin->right_button->width;
492 }
493 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000494
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200495 if (wPreferences.new_style || fwin->titlebar->width != w)
496 fwin->flags.need_texture_remake = 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000497
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200498 wCoreConfigure(fwin->titlebar, x, 0, w, theight);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000499}
500
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200501void wFrameWindowHideButton(WFrameWindow * fwin, int flags)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000502{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200503 if ((flags & WFF_RIGHT_BUTTON) && fwin->right_button) {
504 XUnmapWindow(dpy, fwin->right_button->window);
505 fwin->flags.hide_right_button = 1;
506 }
507
508 if ((flags & WFF_LEFT_BUTTON) && fwin->left_button) {
509 XUnmapWindow(dpy, fwin->left_button->window);
510 fwin->flags.hide_left_button = 1;
511 }
54927f00 kojima1999-05-30 05:10:54 +0000512#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200513 if ((flags & WFF_LANGUAGE_BUTTON) && fwin->language_button) {
514 XUnmapWindow(dpy, fwin->language_button->window);
515 fwin->flags.hide_language_button = 1;
516 }
54927f00 kojima1999-05-30 05:10:54 +0000517#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000518
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200519 if (fwin->titlebar) {
520 if (wPreferences.new_style) {
521 updateTitlebar(fwin);
522 } else {
54927f00 kojima1999-05-30 05:10:54 +0000523#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200524 updateTitlebar(fwin);
54927f00 kojima1999-05-30 05:10:54 +0000525#else
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200526 XClearWindow(dpy, fwin->titlebar->window);
527 wFrameWindowPaint(fwin);
54927f00 kojima1999-05-30 05:10:54 +0000528#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200529 }
530 checkTitleSize(fwin);
531 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000532}
533
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200534void wFrameWindowShowButton(WFrameWindow * fwin, int flags)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000535{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200536 if ((flags & WFF_RIGHT_BUTTON) && fwin->right_button && fwin->flags.hide_right_button) {
6830b057 dan2004-10-12 21:28:27 +0000537
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200538 if (!fwin->flags.rbutton_dont_fit)
539 XMapWindow(dpy, fwin->right_button->window);
54927f00 kojima1999-05-30 05:10:54 +0000540
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200541 fwin->flags.hide_right_button = 0;
542 }
54927f00 kojima1999-05-30 05:10:54 +0000543#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200544 if ((flags & WFF_LANGUAGE_BUTTON) && fwin->language_button && fwin->flags.hide_language_button) {
6830b057 dan2004-10-12 21:28:27 +0000545
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200546 if (!fwin->flags.languagebutton_dont_fit)
547 XMapWindow(dpy, fwin->language_button->window);
6830b057 dan2004-10-12 21:28:27 +0000548
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200549 fwin->flags.hide_language_button = 0;
550 }
54927f00 kojima1999-05-30 05:10:54 +0000551#endif
6830b057 dan2004-10-12 21:28:27 +0000552
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200553 if ((flags & WFF_LEFT_BUTTON) && fwin->left_button && fwin->flags.hide_left_button) {
6830b057 dan2004-10-12 21:28:27 +0000554
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200555 if (!fwin->flags.lbutton_dont_fit)
556 XMapWindow(dpy, fwin->left_button->window);
6830b057 dan2004-10-12 21:28:27 +0000557
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200558 fwin->flags.hide_left_button = 0;
559 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000560
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200561 if (fwin->titlebar) {
562 if (wPreferences.new_style) {
563 updateTitlebar(fwin);
564 } else {
565 XClearWindow(dpy, fwin->titlebar->window);
566 wFrameWindowPaint(fwin);
567 }
568 checkTitleSize(fwin);
569 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000570}
571
9d2e6ef9 scottc1998-09-29 22:36:29 +0000572static void
54927f00 kojima1999-05-30 05:10:54 +0000573#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200574renderTexture(WScreen * scr, WTexture * texture, int width, int height,
575 int bwidth, int bheight, int left, int language, int right,
576 Pixmap * title, Pixmap * lbutton, Pixmap * languagebutton, Pixmap * rbutton)
54927f00 kojima1999-05-30 05:10:54 +0000577#else
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200578renderTexture(WScreen * scr, WTexture * texture, int width, int height,
579 int bwidth, int bheight, int left, int right, Pixmap * title, Pixmap * lbutton, Pixmap * rbutton)
54927f00 kojima1999-05-30 05:10:54 +0000580#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000581{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200582 RImage *img;
583 RImage *limg, *rimg, *mimg;
54927f00 kojima1999-05-30 05:10:54 +0000584#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200585 RImage *timg;
54927f00 kojima1999-05-30 05:10:54 +0000586#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200587 int x, w;
1962d931 kojima1999-05-01 23:15:43 +0000588
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200589 *title = None;
590 *lbutton = None;
591 *rbutton = None;
54927f00 kojima1999-05-30 05:10:54 +0000592#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200593 *languagebutton = None;
54927f00 kojima1999-05-30 05:10:54 +0000594#endif
0261c326 dan1999-01-06 15:22:33 +0000595
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200596 img = wTextureRenderImage(texture, width, height, WREL_FLAT);
597 if (!img) {
598 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
599 return;
600 }
6830b057 dan2004-10-12 21:28:27 +0000601
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200602 if (wPreferences.new_style) {
603 if (left) {
604 limg = RGetSubImage(img, 0, 0, bwidth, bheight);
605 } else
606 limg = NULL;
6830b057 dan2004-10-12 21:28:27 +0000607
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200608 x = 0;
609 w = img->width;
6830b057 dan2004-10-12 21:28:27 +0000610
54927f00 kojima1999-05-30 05:10:54 +0000611#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200612 if (language) {
613 timg = RGetSubImage(img, bwidth * left, 0, bwidth, bheight);
614 } else
615 timg = NULL;
54927f00 kojima1999-05-30 05:10:54 +0000616#endif
6830b057 dan2004-10-12 21:28:27 +0000617
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200618 if (limg) {
619 RBevelImage(limg, RBEV_RAISED2);
620 if (!RConvertImage(scr->rcontext, limg, lbutton)) {
621 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
622 }
623 x += limg->width;
624 w -= limg->width;
625 RReleaseImage(limg);
626 }
54927f00 kojima1999-05-30 05:10:54 +0000627#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200628 if (timg) {
629 RBevelImage(timg, RBEV_RAISED2);
630 if (!RConvertImage(scr->rcontext, timg, languagebutton)) {
631 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
632 }
633 x += timg->width;
634 w -= timg->width;
635 RReleaseImage(timg);
636 }
54927f00 kojima1999-05-30 05:10:54 +0000637#endif
6830b057 dan2004-10-12 21:28:27 +0000638
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200639 if (right) {
640 rimg = RGetSubImage(img, width - bwidth, 0, bwidth, bheight);
641 } else
642 rimg = NULL;
643
644 if (rimg) {
645 RBevelImage(rimg, RBEV_RAISED2);
646 if (!RConvertImage(scr->rcontext, rimg, rbutton)) {
647 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
648 }
649 w -= rimg->width;
650 RReleaseImage(rimg);
651 }
652
653 if (w != width) {
654 mimg = RGetSubImage(img, x, 0, w, img->height);
655 RBevelImage(mimg, RBEV_RAISED2);
656
657 if (!RConvertImage(scr->rcontext, mimg, title)) {
658 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
659 }
660 RReleaseImage(mimg);
661 } else {
662 RBevelImage(img, RBEV_RAISED2);
663
664 if (!RConvertImage(scr->rcontext, img, title)) {
665 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
666 }
667 }
668 } else {
669 RBevelImage(img, RBEV_RAISED2);
670
671 if (!RConvertImage(scr->rcontext, img, title)) {
672 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
673 }
674 }
675
676 RReleaseImage(img);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000677}
678
9af1c6c4 dan1998-10-21 14:43:47 +0000679static void
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200680renderResizebarTexture(WScreen * scr, WTexture * texture, int width, int height, int cwidth, Pixmap * pmap)
da918281 kojima1999-04-12 02:03:58 +0000681{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200682 RImage *img;
683 RColor light;
684 RColor dark;
da918281 kojima1999-04-12 02:03:58 +0000685
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200686 *pmap = None;
da918281 kojima1999-04-12 02:03:58 +0000687
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200688 img = wTextureRenderImage(texture, width, height, WREL_FLAT);
689 if (!img) {
690 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
691 return;
692 }
da918281 kojima1999-04-12 02:03:58 +0000693
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200694 light.alpha = 0;
695 light.red = light.green = light.blue = 80;
da918281 kojima1999-04-12 02:03:58 +0000696
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200697 dark.alpha = 0;
698 dark.red = dark.green = dark.blue = 40;
da918281 kojima1999-04-12 02:03:58 +0000699
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200700 ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
701 ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
da918281 kojima1999-04-12 02:03:58 +0000702
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200703 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
704 ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
da918281 kojima1999-04-12 02:03:58 +0000705
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200706 if (width > 1)
707 ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2,
708 width - cwidth - 2, height - 1, &dark);
709 ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, height - 1, &light);
da918281 kojima1999-04-12 02:03:58 +0000710
7f018497 kojima1999-04-24 20:08:20 +0000711#ifdef SHADOW_RESIZEBAR
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200712 ROperateLine(img, RAddOperation, 0, 1, 0, height - 1, &light);
713 ROperateLine(img, RSubtractOperation, width - 1, 1, width - 1, height - 1, &dark);
714 ROperateLine(img, RSubtractOperation, 0, height - 1, width - 1, height - 1, &dark);
715#endif /* SHADOW_RESIZEBAR */
7f018497 kojima1999-04-24 20:08:20 +0000716
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200717 if (!RConvertImage(scr->rcontext, img, pmap)) {
718 wwarning(_("error rendering image: %s"), RMessageForError(RErrorCode));
719 }
7f018497 kojima1999-04-24 20:08:20 +0000720
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200721 RReleaseImage(img);
da918281 kojima1999-04-12 02:03:58 +0000722}
723
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200724static void updateTexture(WFrameWindow * fwin)
9af1c6c4 dan1998-10-21 14:43:47 +0000725{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200726 int i;
727 unsigned long pixel;
728
729 i = fwin->flags.state;
730 if (fwin->titlebar) {
731 if (fwin->title_texture[i]->any.type != WTEX_SOLID) {
732 XSetWindowBackgroundPixmap(dpy, fwin->titlebar->window, fwin->title_back[i]);
733 if (wPreferences.new_style) {
734 if (fwin->left_button && fwin->lbutton_back[i])
735 XSetWindowBackgroundPixmap(dpy, fwin->left_button->window,
736 fwin->lbutton_back[i]);
54927f00 kojima1999-05-30 05:10:54 +0000737
738#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200739 if (fwin->language_button && fwin->languagebutton_back[i]) {
740 XSetWindowBackgroundPixmap(dpy, fwin->language_button->window,
741 fwin->languagebutton_back[i]);
742 }
54927f00 kojima1999-05-30 05:10:54 +0000743#endif
5230a575 dan2002-10-18 02:56:59 +0000744
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200745 if (fwin->right_button && fwin->rbutton_back[i])
746 XSetWindowBackgroundPixmap(dpy, fwin->right_button->window,
747 fwin->rbutton_back[i]);
748 }
749 } else {
750 pixel = fwin->title_texture[i]->solid.normal.pixel;
751 XSetWindowBackground(dpy, fwin->titlebar->window, pixel);
752 if (wPreferences.new_style) {
753 if (fwin->left_button)
754 XSetWindowBackground(dpy, fwin->left_button->window, pixel);
54927f00 kojima1999-05-30 05:10:54 +0000755#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200756 if (fwin->language_button)
757 XSetWindowBackground(dpy, fwin->language_button->window, pixel);
54927f00 kojima1999-05-30 05:10:54 +0000758#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200759 if (fwin->right_button)
760 XSetWindowBackground(dpy, fwin->right_button->window, pixel);
761 }
762 }
763 XClearWindow(dpy, fwin->titlebar->window);
764
765 if (fwin->left_button) {
766 XClearWindow(dpy, fwin->left_button->window);
767 handleButtonExpose(&fwin->left_button->descriptor, NULL);
768 }
54927f00 kojima1999-05-30 05:10:54 +0000769#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200770 if (fwin->language_button) {
771 XClearWindow(dpy, fwin->language_button->window);
772 handleButtonExpose(&fwin->language_button->descriptor, NULL);
773 }
54927f00 kojima1999-05-30 05:10:54 +0000774#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200775 if (fwin->right_button) {
776 XClearWindow(dpy, fwin->right_button->window);
777 handleButtonExpose(&fwin->right_button->descriptor, NULL);
778 }
779 }
9af1c6c4 dan1998-10-21 14:43:47 +0000780}
781
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200782static void remakeTexture(WFrameWindow * fwin, int state)
9af1c6c4 dan1998-10-21 14:43:47 +0000783{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200784 Pixmap pmap, lpmap, rpmap;
54927f00 kojima1999-05-30 05:10:54 +0000785#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200786 Pixmap tpmap;
54927f00 kojima1999-05-30 05:10:54 +0000787#endif
9af1c6c4 dan1998-10-21 14:43:47 +0000788
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200789 if (fwin->title_texture[state] && fwin->titlebar) {
790 FREE_PIXMAP(fwin->title_back[state]);
791 if (wPreferences.new_style) {
792 FREE_PIXMAP(fwin->lbutton_back[state]);
793 FREE_PIXMAP(fwin->rbutton_back[state]);
54927f00 kojima1999-05-30 05:10:54 +0000794#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200795 FREE_PIXMAP(fwin->languagebutton_back[state]);
54927f00 kojima1999-05-30 05:10:54 +0000796#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200797 }
9af1c6c4 dan1998-10-21 14:43:47 +0000798
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200799 if (fwin->title_texture[state]->any.type != WTEX_SOLID) {
800 int left, right;
801 int width;
54927f00 kojima1999-05-30 05:10:54 +0000802#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200803 int language;
54927f00 kojima1999-05-30 05:10:54 +0000804#endif
9af1c6c4 dan1998-10-21 14:43:47 +0000805
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200806 /* eventually surrounded by if new_style */
807 left = fwin->left_button && !fwin->flags.hide_left_button && !fwin->flags.lbutton_dont_fit;
54927f00 kojima1999-05-30 05:10:54 +0000808#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200809 language = fwin->language_button && !fwin->flags.hide_language_button
810 && !fwin->flags.languagebutton_dont_fit;
54927f00 kojima1999-05-30 05:10:54 +0000811#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200812 right = fwin->right_button && !fwin->flags.hide_right_button
813 && !fwin->flags.rbutton_dont_fit;
da918281 kojima1999-04-12 02:03:58 +0000814
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200815 width = fwin->core->width + 1;
da918281 kojima1999-04-12 02:03:58 +0000816
54927f00 kojima1999-05-30 05:10:54 +0000817#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200818 renderTexture(fwin->screen_ptr, fwin->title_texture[state],
819 width, fwin->titlebar->height,
820 fwin->titlebar->height, fwin->titlebar->height,
821 left, language, right, &pmap, &lpmap, &tpmap, &rpmap);
54927f00 kojima1999-05-30 05:10:54 +0000822#else
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200823 renderTexture(fwin->screen_ptr, fwin->title_texture[state],
824 width, fwin->titlebar->height,
825 fwin->titlebar->height, fwin->titlebar->height,
826 left, right, &pmap, &lpmap, &rpmap);
54927f00 kojima1999-05-30 05:10:54 +0000827#endif
da918281 kojima1999-04-12 02:03:58 +0000828
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200829 fwin->title_back[state] = pmap;
830 if (wPreferences.new_style) {
831 fwin->lbutton_back[state] = lpmap;
832 fwin->rbutton_back[state] = rpmap;
54927f00 kojima1999-05-30 05:10:54 +0000833#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200834 fwin->languagebutton_back[state] = tpmap;
54927f00 kojima1999-05-30 05:10:54 +0000835#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200836 }
837 }
838 }
839 if (fwin->resizebar_texture && fwin->resizebar_texture[0]
840 && fwin->resizebar && state == 0) {
841
842 FREE_PIXMAP(fwin->resizebar_back[0]);
843
844 if (fwin->resizebar_texture[0]->any.type != WTEX_SOLID) {
845
846 renderResizebarTexture(fwin->screen_ptr,
847 fwin->resizebar_texture[0],
848 fwin->resizebar->width,
849 fwin->resizebar->height, fwin->resizebar_corner_width, &pmap);
850
851 fwin->resizebar_back[0] = pmap;
852 }
853
854 /* this part should be in updateTexture() */
855 if (fwin->resizebar_texture[0]->any.type != WTEX_SOLID) {
856 XSetWindowBackgroundPixmap(dpy, fwin->resizebar->window, fwin->resizebar_back[0]);
857 } else {
858 XSetWindowBackground(dpy, fwin->resizebar->window,
859 fwin->resizebar_texture[0]->solid.normal.pixel);
860 }
861 XClearWindow(dpy, fwin->resizebar->window);
862 }
9af1c6c4 dan1998-10-21 14:43:47 +0000863}
864
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200865void wFrameWindowPaint(WFrameWindow * fwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000866{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200867 WScreen *scr = fwin->screen_ptr;
868 int state;
869
870 state = fwin->flags.state;
871
872 if (fwin->flags.is_client_window_frame)
873 fwin->flags.justification = wPreferences.title_justification;
874
875 if (fwin->flags.need_texture_remake) {
876 int i;
877
878 fwin->flags.need_texture_remake = 0;
879 fwin->flags.need_texture_change = 0;
880
881 if (fwin->flags.single_texture) {
882 remakeTexture(fwin, 0);
883 updateTexture(fwin);
884 } else {
885 /* first render the texture for the current state... */
886 remakeTexture(fwin, state);
887 /* ... and paint it */
888 updateTexture(fwin);
889
890 for (i = 0; i < 3; i++) {
891 if (i != state) {
892 remakeTexture(fwin, i);
893 }
894 }
895 }
896 }
897
898 if (fwin->flags.need_texture_change) {
899 fwin->flags.need_texture_change = 0;
900
901 updateTexture(fwin);
902 }
903
904 if (fwin->titlebar && !fwin->flags.repaint_only_resizebar
905 && fwin->title_texture[state]->any.type == WTEX_SOLID) {
906 wDrawBevel(fwin->titlebar->window, fwin->titlebar->width,
907 fwin->titlebar->height, (WTexSolid *) fwin->title_texture[state], WREL_RAISED);
908 }
909
910 if (fwin->resizebar && !fwin->flags.repaint_only_titlebar
911 && fwin->resizebar_texture[0]->any.type == WTEX_SOLID) {
912 Window win;
913 int w, h;
914 int cw;
915 GC light_gc, dim_gc;
916 WTexSolid *texture = (WTexSolid *) fwin->resizebar_texture[0];
917
918 w = fwin->resizebar->width;
919 h = fwin->resizebar->height;
920 cw = fwin->resizebar_corner_width;
921 light_gc = texture->light_gc;
922 dim_gc = texture->dim_gc;
923 win = fwin->resizebar->window;
924
925 XDrawLine(dpy, win, dim_gc, 0, 0, w, 0);
926 XDrawLine(dpy, win, light_gc, 0, 1, w, 1);
927
928 XDrawLine(dpy, win, dim_gc, cw, 2, cw, h);
929 XDrawLine(dpy, win, light_gc, cw + 1, 2, cw + 1, h);
930
931 XDrawLine(dpy, win, dim_gc, w - cw - 2, 2, w - cw - 2, h);
932 XDrawLine(dpy, win, light_gc, w - cw - 1, 2, w - cw - 1, h);
6830b057 dan2004-10-12 21:28:27 +0000933
9d2e6ef9 scottc1998-09-29 22:36:29 +0000934#ifdef SHADOW_RESIZEBAR
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200935 XDrawLine(dpy, win, light_gc, 0, 1, 0, h - 1);
936 XDrawLine(dpy, win, dim_gc, w - 1, 2, w - 1, h - 1);
937 XDrawLine(dpy, win, dim_gc, 1, h - 1, cw, h - 1);
938 XDrawLine(dpy, win, dim_gc, cw + 2, h - 1, w - cw - 2, h - 1);
939 XDrawLine(dpy, win, dim_gc, w - cw, h - 1, w - 1, h - 1);
940#endif /* SHADOW_RESIZEBAR */
941 }
942
943 if (fwin->titlebar && !fwin->flags.repaint_only_resizebar) {
944 int x, y, w, h;
945 int lofs = 6, rofs = 6;
946 int titlelen;
947 int allButtons = 1;
948
949 if (!wPreferences.new_style) {
950 if (fwin->left_button && !fwin->flags.hide_left_button && !fwin->flags.lbutton_dont_fit)
951 lofs += fwin->left_button->width + 3;
952 else
953 allButtons = 0;
54927f00 kojima1999-05-30 05:10:54 +0000954
955#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200956 if (fwin->language_button && !fwin->flags.hide_language_button
957 && !fwin->flags.languagebutton_dont_fit)
958 lofs += fwin->language_button->width;
959 else
960 allButtons = 0;
54927f00 kojima1999-05-30 05:10:54 +0000961#endif
0bb76c0a dan2002-10-18 22:17:20 +0000962
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200963 if (fwin->right_button && !fwin->flags.hide_right_button && !fwin->flags.rbutton_dont_fit)
964 rofs += fwin->right_button->width + 3;
965 else
966 allButtons = 0;
967 }
54927f00 kojima1999-05-30 05:10:54 +0000968#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200969 fwin->languagebutton_image = scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
54927f00 kojima1999-05-30 05:10:54 +0000970#endif
971
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200972 if (fwin->title) {
973 Drawable buf;
974 char *title;
975
976 title = ShrinkString(*fwin->font, fwin->title, fwin->titlebar->width - lofs - rofs);
977 titlelen = strlen(title);
978 w = WMWidthOfString(*fwin->font, title, titlelen);
979
980 switch (fwin->flags.justification) {
981 case WTJ_LEFT:
982 x = lofs;
983 break;
984
985 case WTJ_RIGHT:
986 x = fwin->titlebar->width - w - rofs;
987 break;
988
989 default:
990 if (!allButtons)
991 x = lofs + (fwin->titlebar->width - w - lofs - rofs) / 2;
992 else
993 x = (fwin->titlebar->width - w) / 2;
994 break;
995 }
996
997 y = *fwin->title_clearance + TITLEBAR_EXTEND_SPACE;
998 h = WMFontHeight(*fwin->font);
999
1000 /* We use a w+2 buffer to have an extra pixel on the left and
1001 * another one on the right. This is because for some odd reason,
1002 * sometimes when using AA fonts (when libfreetype2 is compiled
1003 * with bytecode interpreter turned off), some fonts are drawn
1004 * starting from x = -1 not from 0 as requested. Observed with
1005 * capital A letter on the bold 'trebuchet ms' font. -Dan
1006 */
1007 buf = XCreatePixmap(dpy, fwin->titlebar->window, w + 2, h, scr->w_depth);
1008
1009 XSetClipMask(dpy, scr->copy_gc, None);
1010
1011 if (fwin->title_texture[state]->any.type != WTEX_SOLID) {
1012 XCopyArea(dpy, fwin->title_back[state], buf, scr->copy_gc,
1013 x - 1, y, w + 2, h, 0, 0);
1014 } else {
1015 XSetForeground(dpy, scr->copy_gc, fwin->title_texture[state]->solid.normal.pixel);
1016 XFillRectangle(dpy, buf, scr->copy_gc, 0, 0, w + 2, h);
1017 }
1018
1019 /*XDrawRectangle(dpy, buf, WMColorGC(scr->white),1,0,w,h-1); */
1020 WMDrawString(scr->wmscreen, buf, fwin->title_color[state],
1021 *fwin->font, 1, 0, title, titlelen);
1022
1023 XCopyArea(dpy, buf, fwin->titlebar->window, scr->copy_gc, 0, 0, w + 2, h, x - 1, y);
1024
1025 XFreePixmap(dpy, buf);
1026
1027 wfree(title);
1028 }
1029
1030 if (fwin->left_button)
1031 handleButtonExpose(&fwin->left_button->descriptor, NULL);
1032 if (fwin->right_button)
1033 handleButtonExpose(&fwin->right_button->descriptor, NULL);
54927f00 kojima1999-05-30 05:10:54 +00001034#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001035 if (fwin->language_button)
1036 handleButtonExpose(&fwin->language_button->descriptor, NULL);
3bed15d6 dan2002-10-17 20:26:30 +00001037#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001038 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001039}
1040
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001041static void reconfigure(WFrameWindow * fwin, int x, int y, int width, int height, Bool dontMove)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001042{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001043 int k = (wPreferences.new_style ? 4 : 3);
1044 int resizedHorizontally = 0;
1045
1046 if (dontMove)
1047 XResizeWindow(dpy, fwin->core->window, width, height);
1048 else
1049 XMoveResizeWindow(dpy, fwin->core->window, x, y, width, height);
1050
1051 /*
1052 if (fwin->core->height != height && fwin->resizebar)
1053 XMoveWindow(dpy, fwin->resizebar->window, 0,
1054 height - fwin->resizebar->height);
1055 */
1056 if (fwin->core->width != width) {
1057 fwin->flags.need_texture_remake = 1;
1058 resizedHorizontally = 1;
1059 }
1060
1061 fwin->core->width = width;
1062 fwin->core->height = height;
1063
1064 if (fwin->titlebar && resizedHorizontally) {
1065 /* Check if the titlebar is wide enough to hold the buttons.
1066 * Temporarily remove them if can't
1067 */
1068 if (fwin->left_button) {
1069 if (width < fwin->top_width * k && !fwin->flags.lbutton_dont_fit) {
1070
1071 if (!fwin->flags.hide_left_button) {
1072 XUnmapWindow(dpy, fwin->left_button->window);
1073 }
1074 fwin->flags.lbutton_dont_fit = 1;
1075 } else if (width >= fwin->top_width * k && fwin->flags.lbutton_dont_fit) {
1076
1077 if (!fwin->flags.hide_left_button) {
1078 XMapWindow(dpy, fwin->left_button->window);
1079 }
1080 fwin->flags.lbutton_dont_fit = 0;
1081 }
1082 }
54927f00 kojima1999-05-30 05:10:54 +00001083#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001084 if (fwin->language_button) {
1085 if (width < fwin->top_width * k && !fwin->flags.languagebutton_dont_fit) {
1086
1087 if (!fwin->flags.hide_language_button) {
1088 XUnmapWindow(dpy, fwin->language_button->window);
1089 }
1090 fwin->flags.languagebutton_dont_fit = 1;
1091 } else if (width >= fwin->top_width * k && fwin->flags.languagebutton_dont_fit) {
1092
1093 if (!fwin->flags.hide_language_button) {
1094 XMapWindow(dpy, fwin->language_button->window);
1095 }
1096 fwin->flags.languagebutton_dont_fit = 0;
1097 }
1098 }
54927f00 kojima1999-05-30 05:10:54 +00001099#endif
6830b057 dan2004-10-12 21:28:27 +00001100
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001101 if (fwin->right_button) {
1102 if (width < fwin->top_width * 2 && !fwin->flags.rbutton_dont_fit) {
1103
1104 if (!fwin->flags.hide_right_button) {
1105 XUnmapWindow(dpy, fwin->right_button->window);
1106 }
1107 fwin->flags.rbutton_dont_fit = 1;
1108 } else if (width >= fwin->top_width * 2 && fwin->flags.rbutton_dont_fit) {
1109
1110 if (!fwin->flags.hide_right_button) {
1111 XMapWindow(dpy, fwin->right_button->window);
1112 }
1113 fwin->flags.rbutton_dont_fit = 0;
1114 }
1115 }
1116
1117 if (wPreferences.new_style) {
1118 if (fwin->right_button)
1119 XMoveWindow(dpy, fwin->right_button->window,
1120 width - fwin->right_button->width + 1, 0);
1121 } else {
1122 if (fwin->right_button)
1123 XMoveWindow(dpy, fwin->right_button->window,
1124 width - fwin->right_button->width - 3,
1125 (fwin->titlebar->height - fwin->right_button->height) / 2);
1126 }
1127 updateTitlebar(fwin);
1128 checkTitleSize(fwin);
1129 }
1130
1131 if (fwin->resizebar) {
1132 wCoreConfigure(fwin->resizebar, 0,
1133 fwin->core->height - fwin->resizebar->height,
1134 fwin->core->width, fwin->resizebar->height);
1135
1136 fwin->resizebar_corner_width = RESIZEBAR_CORNER_WIDTH;
1137 if (fwin->core->width < RESIZEBAR_CORNER_WIDTH * 2 + RESIZEBAR_MIN_WIDTH) {
1138 fwin->resizebar_corner_width = fwin->core->width / 2;
1139 }
1140 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001141}
1142
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001143void wFrameWindowConfigure(WFrameWindow * fwin, int x, int y, int width, int height)
0261c326 dan1999-01-06 15:22:33 +00001144{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001145 reconfigure(fwin, x, y, width, height, False);
0261c326 dan1999-01-06 15:22:33 +00001146}
9d2e6ef9 scottc1998-09-29 22:36:29 +00001147
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001148void wFrameWindowResize(WFrameWindow * fwin, int width, int height)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001149{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001150 reconfigure(fwin, 0, 0, width, height, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001151}
1152
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001153int wFrameWindowChangeTitle(WFrameWindow * fwin, char *new_title)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001154{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001155 /* check if the title is the same as before */
1156 if (fwin->title) {
1157 if (new_title && (strcmp(fwin->title, new_title) == 0)) {
1158 return 0;
1159 }
1160 } else {
1161 if (!new_title)
1162 return 0;
1163 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001164
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001165 if (fwin->title)
1166 wfree(fwin->title);
d6feaa1c kojima2001-06-06 19:48:31 +00001167
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001168 fwin->title = wstrdup(new_title);
d6feaa1c kojima2001-06-06 19:48:31 +00001169
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001170 if (fwin->titlebar) {
1171 XClearWindow(dpy, fwin->titlebar->window);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001172
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001173 wFrameWindowPaint(fwin);
1174 }
1175 checkTitleSize(fwin);
d6feaa1c kojima2001-06-06 19:48:31 +00001176
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001177 return 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001178}
1179
54927f00 kojima1999-05-30 05:10:54 +00001180#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001181void wFrameWindowUpdateLanguageButton(WFrameWindow * fwin)
54927f00 kojima1999-05-30 05:10:54 +00001182{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001183 paintButton(fwin->language_button, fwin->title_texture[fwin->flags.state],
1184 WMColorPixel(fwin->title_color[fwin->flags.state]), fwin->languagebutton_image, True);
54927f00 kojima1999-05-30 05:10:54 +00001185}
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001186#endif /* XKB_BUTTON_HINT */
416e3a82 dan1999-01-25 19:06:50 +00001187
9d2e6ef9 scottc1998-09-29 22:36:29 +00001188/*********************************************************************/
1189
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001190static void handleExpose(WObjDescriptor * desc, XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001191{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001192 WFrameWindow *fwin = (WFrameWindow *) desc->parent;
1193
1194 if (fwin->titlebar && fwin->titlebar->window == event->xexpose.window)
1195 fwin->flags.repaint_only_titlebar = 1;
1196 if (fwin->resizebar && fwin->resizebar->window == event->xexpose.window)
1197 fwin->flags.repaint_only_resizebar = 1;
1198 wFrameWindowPaint(fwin);
1199 fwin->flags.repaint_only_titlebar = 0;
1200 fwin->flags.repaint_only_resizebar = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001201}
1202
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001203static void checkTitleSize(WFrameWindow * fwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001204{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001205 int width;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001206
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001207 if (!fwin->title) {
1208 fwin->flags.incomplete_title = 0;
1209 return;
1210 }
6830b057 dan2004-10-12 21:28:27 +00001211
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001212 if (!fwin->titlebar) {
1213 fwin->flags.incomplete_title = 1;
1214 return;
1215 } else {
1216 width = fwin->titlebar->width - 6 - 6;
1217 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001218
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001219 if (!wPreferences.new_style) {
1220 if (fwin->left_button && !fwin->flags.hide_left_button && !fwin->flags.lbutton_dont_fit)
1221 width -= fwin->left_button->width + 3;
54927f00 kojima1999-05-30 05:10:54 +00001222
1223#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001224 if (fwin->language_button && !fwin->flags.hide_language_button
1225 && !fwin->flags.languagebutton_dont_fit)
1226 width -= fwin->language_button->width + 3;
54927f00 kojima1999-05-30 05:10:54 +00001227#endif
6830b057 dan2004-10-12 21:28:27 +00001228
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001229 if (fwin->right_button && !fwin->flags.hide_right_button && !fwin->flags.rbutton_dont_fit)
1230 width -= fwin->right_button->width + 3;
1231 }
1232 if (WMWidthOfString(*fwin->font, fwin->title, strlen(fwin->title)) > width) {
1233 fwin->flags.incomplete_title = 1;
1234 } else {
1235 fwin->flags.incomplete_title = 0;
1236 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001237}
1238
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001239static void paintButton(WCoreWindow * button, WTexture * texture, unsigned long color, WPixmap * image, int pushed)
6830b057 dan2004-10-12 21:28:27 +00001240{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001241 WScreen *scr = button->screen_ptr;
1242 GC copy_gc = scr->copy_gc;
1243 int x = 0, y = 0, d = 0;
1244 int left = 0, width = 0;
1245
1246 /* setup stuff according to the state */
1247 if (pushed) {
1248 if (image) {
1249 if (image->width >= image->height * 2) {
1250 /* the image contains 2 pictures: the second is for the
1251 * pushed state */
1252 width = image->width / 2;
1253 left = image->width / 2;
1254 } else {
1255 width = image->width;
1256 }
1257 }
1258 XSetClipMask(dpy, copy_gc, None);
1259 XSetForeground(dpy, copy_gc, scr->white_pixel);
1260 d = 1;
1261 if (wPreferences.new_style) {
1262 XFillRectangle(dpy, button->window, copy_gc, 0, 0, button->width - 1, button->height - 1);
1263 XSetForeground(dpy, copy_gc, scr->black_pixel);
1264 XDrawRectangle(dpy, button->window, copy_gc, 0, 0, button->width - 1, button->height - 1);
1265 } else {
1266 XFillRectangle(dpy, button->window, copy_gc, 0, 0, button->width, button->height);
1267 XSetForeground(dpy, copy_gc, scr->black_pixel);
1268 XDrawRectangle(dpy, button->window, copy_gc, 0, 0, button->width, button->height);
1269 }
1270 } else {
1271 XClearWindow(dpy, button->window);
1272
1273 if (image) {
1274 if (image->width >= image->height * 2)
1275 width = image->width / 2;
1276 else
1277 width = image->width;
1278 }
1279 d = 0;
1280
1281 if (wPreferences.new_style) {
1282 if (texture->any.type == WTEX_SOLID || pushed) {
1283 wDrawBevel(button->window, button->width, button->height,
1284 (WTexSolid *) texture, WREL_RAISED);
1285 }
1286 } else {
1287 wDrawBevel(button->window, button->width, button->height,
1288 scr->widget_texture, WREL_RAISED);
1289 }
1290 }
1291
1292 if (image) {
1293 /* display image */
1294 XSetClipMask(dpy, copy_gc, image->mask);
1295 x = (button->width - width) / 2 + d;
1296 y = (button->height - image->height) / 2 + d;
1297 XSetClipOrigin(dpy, copy_gc, x - left, y);
1298 if (!wPreferences.new_style) {
1299 XSetForeground(dpy, copy_gc, scr->black_pixel);
1300 if (!pushed) {
1301 if (image->depth == 1)
1302 XCopyPlane(dpy, image->image, button->window, copy_gc,
1303 left, 0, width, image->height, x, y, 1);
1304 else
1305 XCopyArea(dpy, image->image, button->window, copy_gc,
1306 left, 0, width, image->height, x, y);
1307 } else {
1308 XSetForeground(dpy, copy_gc, scr->dark_pixel);
1309 XFillRectangle(dpy, button->window, copy_gc, 0, 0, button->width, button->height);
1310 }
1311 } else {
1312 if (pushed) {
1313 XSetForeground(dpy, copy_gc, scr->black_pixel);
1314 } else {
1315 XSetForeground(dpy, copy_gc, color);
1316 XSetBackground(dpy, copy_gc, texture->any.color.pixel);
1317 }
1318 XFillRectangle(dpy, button->window, copy_gc, 0, 0, button->width, button->height);
1319 }
1320 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001321}
1322
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001323static void handleButtonExpose(WObjDescriptor * desc, XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001324{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001325 WFrameWindow *fwin = (WFrameWindow *) desc->parent;
1326 WCoreWindow *button = (WCoreWindow *) desc->self;
416e3a82 dan1999-01-25 19:06:50 +00001327
54927f00 kojima1999-05-30 05:10:54 +00001328#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001329 if (button == fwin->language_button) {
1330 if (wPreferences.modelock) {
1331 paintButton(button, fwin->title_texture[fwin->flags.state],
1332 WMColorPixel(fwin->title_color[fwin->flags.state]),
1333 fwin->languagebutton_image, False);
1334 }
1335 } else
54927f00 kojima1999-05-30 05:10:54 +00001336#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001337 if (button == fwin->left_button) {
1338 paintButton(button, fwin->title_texture[fwin->flags.state],
1339 WMColorPixel(fwin->title_color[fwin->flags.state]), fwin->lbutton_image, False);
1340 } else {
1341 paintButton(button, fwin->title_texture[fwin->flags.state],
1342 WMColorPixel(fwin->title_color[fwin->flags.state]), fwin->rbutton_image, False);
1343 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001344}
1345
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001346static void titlebarMouseDown(WObjDescriptor * desc, XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001347{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001348 WFrameWindow *fwin = desc->parent;
1349 WCoreWindow *titlebar = desc->self;
1350
1351 if (IsDoubleClick(fwin->core->screen_ptr, event)) {
1352 if (fwin->on_dblclick_titlebar) {
1353 (*fwin->on_dblclick_titlebar) (titlebar, fwin->child, event);
1354 }
1355 } else {
1356 if (fwin->on_mousedown_titlebar) {
1357 (*fwin->on_mousedown_titlebar) (titlebar, fwin->child, event);
1358 }
1359 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001360}
1361
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001362static void resizebarMouseDown(WObjDescriptor * desc, XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001363{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001364 WFrameWindow *fwin = desc->parent;
1365 WCoreWindow *resizebar = desc->self;
6830b057 dan2004-10-12 21:28:27 +00001366
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001367 if (fwin->on_mousedown_resizebar)
1368 (*fwin->on_mousedown_resizebar) (resizebar, fwin->child, event);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001369}
1370
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001371static void buttonMouseDown(WObjDescriptor * desc, XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001372{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001373 WFrameWindow *fwin = desc->parent;
1374 WCoreWindow *button = desc->self;
1375 WPixmap *image;
1376 XEvent ev;
1377 int done = 0, execute = 1;
1378 WTexture *texture;
1379 unsigned long pixel;
1380 int clickButton = event->xbutton.button;
1381
1382 if (IsDoubleClick(fwin->core->screen_ptr, event)) {
1383 if (button == fwin->right_button && fwin->on_dblclick_right) {
1384 (*fwin->on_dblclick_right) (button, fwin->child, event);
1385 }
1386 return;
1387 }
1388
1389 if (button == fwin->left_button) {
1390 image = fwin->lbutton_image;
1391 } else {
1392 image = fwin->rbutton_image;
1393 }
54927f00 kojima1999-05-30 05:10:54 +00001394#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001395 if (button == fwin->language_button) {
1396 if (!wPreferences.modelock)
1397 return;
1398 image = fwin->languagebutton_image;
1399 }
54927f00 kojima1999-05-30 05:10:54 +00001400#endif
6830b057 dan2004-10-12 21:28:27 +00001401
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001402 pixel = WMColorPixel(fwin->title_color[fwin->flags.state]);
1403 texture = fwin->title_texture[fwin->flags.state];
1404 paintButton(button, texture, pixel, image, True);
1405
1406 while (!done) {
1407 WMMaskEvent(dpy, LeaveWindowMask | EnterWindowMask | ButtonReleaseMask
1408 | ButtonPressMask | ExposureMask, &ev);
1409 switch (ev.type) {
1410 case LeaveNotify:
1411 execute = 0;
1412 paintButton(button, texture, pixel, image, False);
1413 break;
1414
1415 case EnterNotify:
1416 execute = 1;
1417 paintButton(button, texture, pixel, image, True);
1418 break;
1419
1420 case ButtonPress:
1421 break;
1422
1423 case ButtonRelease:
1424 if (ev.xbutton.button == clickButton)
1425 done = 1;
1426 break;
1427
1428 default:
1429 WMHandleEvent(&ev);
1430 }
1431 }
1432 paintButton(button, texture, pixel, image, False);
1433
1434 if (execute) {
1435 if (button == fwin->left_button) {
1436 if (fwin->on_click_left)
1437 (*fwin->on_click_left) (button, fwin->child, &ev);
1438 } else if (button == fwin->right_button) {
1439 if (fwin->on_click_right)
1440 (*fwin->on_click_right) (button, fwin->child, &ev);
1441 }
54927f00 kojima1999-05-30 05:10:54 +00001442#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001443 else if (button == fwin->language_button) {
1444 if (fwin->on_click_language)
1445 (*fwin->on_click_language) (button, fwin->child, &ev);
1446 }
54927f00 kojima1999-05-30 05:10:54 +00001447#endif
1448
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001449 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001450}