]> Dogcows Code - chaz/openbox/blob - src/Toolbar.cc
temprary fix for the memleaks in ::load() and ::set* when using ostrstreams. Need...
[chaz/openbox] / src / Toolbar.cc
1 // Toolbar.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 // stupid macros needed to access some functions in version 2 of the GNU C
24 // library
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif // _GNU_SOURCE
28
29 #ifdef HAVE_CONFIG_H
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
32
33 #include "i18n.h"
34 #include "openbox.h"
35 #include "Clientmenu.h"
36 #include "Iconmenu.h"
37 #include "Rootmenu.h"
38 #include "Screen.h"
39 #include "Toolbar.h"
40 #include "Window.h"
41 #include "Workspace.h"
42 #include "Workspacemenu.h"
43
44 #include <X11/keysym.h>
45
46 #ifdef HAVE_STRING_H
47 # include <string.h>
48 #endif // HAVE_STRING_H
49
50 #ifdef HAVE_STDIO_H
51 # include <stdio.h>
52 #endif // HAVE_STDIO_H
53
54 #ifdef TIME_WITH_SYS_TIME
55 # include <sys/time.h>
56 # include <time.h>
57 #else // !TIME_WITH_SYS_TIME
58 # ifdef HAVE_SYS_TIME_H
59 # include <sys/time.h>
60 # else // !HAVE_SYS_TIME_H
61 # include <time.h>
62 # endif // HAVE_SYS_TIME_H
63 #endif // TIME_WITH_SYS_TIME
64
65 #include <strstream>
66 #include <string>
67
68 Toolbar::Toolbar(BScreen &scrn, Resource &conf) : screen(scrn),
69 openbox(scrn.getOpenbox()), config(conf)
70 {
71 // default values
72 m_width_percent =66;
73 m_placement = BottomCenter;
74 m_ontop = false;
75 m_hidden = m_autohide = false;
76 load();
77
78 // get the clock updating every minute
79 clock_timer = new BTimer(openbox, *this);
80 timeval now;
81 gettimeofday(&now, 0);
82 clock_timer->setTimeout((60 - (now.tv_sec % 60)) * 1000);
83 clock_timer->start();
84
85 hide_handler.toolbar = this;
86 hide_timer = new BTimer(openbox, hide_handler);
87 hide_timer->setTimeout(openbox.getAutoRaiseDelay());
88 hide_timer->fireOnce(True);
89
90 image_ctrl = screen.getImageControl();
91
92 m_editing = False;
93 new_workspace_name = (char *) 0;
94 new_name_pos = 0;
95 frame.grab_x = frame.grab_y = 0;
96
97 toolbarmenu = new Toolbarmenu(*this);
98
99 display = openbox.getXDisplay();
100 XSetWindowAttributes attrib;
101 unsigned long create_mask = CWBackPixmap | CWBackPixel | CWBorderPixel |
102 CWColormap | CWOverrideRedirect | CWEventMask;
103 attrib.background_pixmap = None;
104 attrib.background_pixel = attrib.border_pixel =
105 screen.getBorderColor()->getPixel();
106 attrib.colormap = screen.getColormap();
107 attrib.override_redirect = True;
108 attrib.event_mask = ButtonPressMask | ButtonReleaseMask |
109 EnterWindowMask | LeaveWindowMask;
110
111 frame.window =
112 XCreateWindow(display, screen.getRootWindow(), 0, 0, 1, 1, 0,
113 screen.getDepth(), InputOutput, screen.getVisual(),
114 create_mask, &attrib);
115 openbox.saveToolbarSearch(frame.window, this);
116
117 attrib.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask |
118 KeyPressMask | EnterWindowMask;
119
120 frame.workspace_label =
121 XCreateWindow(display, frame.window, 0, 0, 1, 1, 0, screen.getDepth(),
122 InputOutput, screen.getVisual(), create_mask, &attrib);
123 openbox.saveToolbarSearch(frame.workspace_label, this);
124
125 frame.window_label =
126 XCreateWindow(display, frame.window, 0, 0, 1, 1, 0, screen.getDepth(),
127 InputOutput, screen.getVisual(), create_mask, &attrib);
128 openbox.saveToolbarSearch(frame.window_label, this);
129
130 frame.clock =
131 XCreateWindow(display, frame.window, 0, 0, 1, 1, 0, screen.getDepth(),
132 InputOutput, screen.getVisual(), create_mask, &attrib);
133 openbox.saveToolbarSearch(frame.clock, this);
134
135 frame.psbutton =
136 XCreateWindow(display ,frame.window, 0, 0, 1, 1, 0, screen.getDepth(),
137 InputOutput, screen.getVisual(), create_mask, &attrib);
138 openbox.saveToolbarSearch(frame.psbutton, this);
139
140 frame.nsbutton =
141 XCreateWindow(display ,frame.window, 0, 0, 1, 1, 0, screen.getDepth(),
142 InputOutput, screen.getVisual(), create_mask, &attrib);
143 openbox.saveToolbarSearch(frame.nsbutton, this);
144
145 frame.pwbutton =
146 XCreateWindow(display ,frame.window, 0, 0, 1, 1, 0, screen.getDepth(),
147 InputOutput, screen.getVisual(), create_mask, &attrib);
148 openbox.saveToolbarSearch(frame.pwbutton, this);
149
150 frame.nwbutton =
151 XCreateWindow(display ,frame.window, 0, 0, 1, 1, 0, screen.getDepth(),
152 InputOutput, screen.getVisual(), create_mask, &attrib);
153 openbox.saveToolbarSearch(frame.nwbutton, this);
154
155 frame.base = frame.label = frame.wlabel = frame.clk = frame.button =
156 frame.pbutton = None;
157
158 reconfigure();
159 mapToolbar();
160 }
161
162 int Toolbar::getX() const {
163 return ((m_hidden) ? frame.x_hidden : frame.x);
164 }
165
166 int Toolbar::getY() const {
167 if (screen.hideToolbar()) return screen.size().h();
168 else if (m_hidden) return frame.y_hidden;
169 else return frame.y;
170 }
171
172 unsigned int Toolbar::getExposedHeight() const {
173 if (screen.hideToolbar()) return 0;
174 else if (m_autohide) return frame.bevel_w;
175 else return frame.height;
176 }
177
178 void Toolbar::mapToolbar(){
179 if (!screen.hideToolbar()) {
180 //not hidden, so windows should not maximize over the toolbar
181 XMapSubwindows(display, frame.window);
182 XMapWindow(display, frame.window);
183 }
184 }
185
186 void Toolbar::unMapToolbar(){
187 //hidden so we can maximize over the toolbar
188 XUnmapWindow(display, frame.window);
189 }
190
191 Toolbar::~Toolbar() {
192 unMapToolbar();
193 if (frame.base) image_ctrl->removeImage(frame.base);
194 if (frame.label) image_ctrl->removeImage(frame.label);
195 if (frame.wlabel) image_ctrl->removeImage(frame.wlabel);
196 if (frame.clk) image_ctrl->removeImage(frame.clk);
197 if (frame.button) image_ctrl->removeImage(frame.button);
198 if (frame.pbutton) image_ctrl->removeImage(frame.pbutton);
199
200 openbox.removeToolbarSearch(frame.window);
201 openbox.removeToolbarSearch(frame.workspace_label);
202 openbox.removeToolbarSearch(frame.window_label);
203 openbox.removeToolbarSearch(frame.clock);
204 openbox.removeToolbarSearch(frame.psbutton);
205 openbox.removeToolbarSearch(frame.nsbutton);
206 openbox.removeToolbarSearch(frame.pwbutton);
207 openbox.removeToolbarSearch(frame.nwbutton);
208
209 XDestroyWindow(display, frame.workspace_label);
210 XDestroyWindow(display, frame.window_label);
211 XDestroyWindow(display, frame.clock);
212
213 XDestroyWindow(display, frame.window);
214
215 delete hide_timer;
216 delete clock_timer;
217 delete toolbarmenu;
218 }
219
220
221 void Toolbar::setOnTop(bool b) {
222 m_ontop = b;
223 ostrstream s;
224 s << "session.screen" << screen.getScreenNumber() << ".toolbar.onTop" << ends;
225 config.setValue(s.str(), m_ontop ? "True" : "False");
226 s.rdbuf()->freeze(0);
227 }
228
229 void Toolbar::setAutoHide(bool b) {
230 m_autohide = b;
231 ostrstream s;
232 s << "session.screen" << screen.getScreenNumber() << ".toolbar.autoHide" <<
233 ends;
234 config.setValue(s.str(), m_autohide ? "True" : "False");
235 s.rdbuf()->freeze(0);
236 }
237
238 void Toolbar::setWidthPercent(int w) {
239 m_width_percent = w;
240 ostrstream s;
241 s << "session.screen" << screen.getScreenNumber() << ".toolbar.widthPercent"
242 << ends;
243 config.setValue(s.str(), m_width_percent);
244 s.rdbuf()->freeze(0);
245 }
246
247 void Toolbar::setPlacement(int p) {
248 m_placement = p;
249 ostrstream s;
250 s << "session.screen" << screen.getScreenNumber() << ".toolbar.placement" <<
251 ends;
252 const char *placement;
253 switch (m_placement) {
254 case TopLeft: placement = "TopLeft"; break;
255 case BottomLeft: placement = "BottomLeft"; break;
256 case TopCenter: placement = "TopCenter"; break;
257 case TopRight: placement = "TopRight"; break;
258 case BottomRight: placement = "BottomRight"; break;
259 case BottomCenter: default: placement = "BottomCenter"; break;
260 }
261 config.setValue(s.str(), placement);
262 s.rdbuf()->freeze(0);
263 }
264
265 void Toolbar::save() {
266 setOnTop(m_ontop);
267 setAutoHide(m_autohide);
268 setWidthPercent(m_width_percent);
269 setPlacement(m_placement);
270 }
271
272 void Toolbar::load() {
273 std::ostrstream rscreen, rname, rclass;
274 std::string s;
275 bool b;
276 long l;
277 rscreen << "session.screen" << screen.getScreenNumber() << '.' << ends;
278
279 rname << rscreen.str() << "toolbar.widthPercent" << ends;
280 rclass << rscreen.str() << "Toolbar.WidthPercent" << ends;
281 if (config.getValue(rname.str(), rclass.str(), l) && (l > 0 && l <= 100))
282 m_width_percent = l;
283
284 rname.seekp(0); rclass.seekp(0);
285 rname << rscreen.str() << "toolbar.placement" << ends;
286 rclass << rscreen.str() << "Toolbar.Placement" << ends;
287 if (config.getValue(rname.str(), rclass.str(), s)) {
288 if (0 == strncasecmp(s.c_str(), "TopLeft", s.length()))
289 m_placement = TopLeft;
290 else if (0 == strncasecmp(s.c_str(), "BottomLeft", s.length()))
291 m_placement = BottomLeft;
292 else if (0 == strncasecmp(s.c_str(), "TopCenter", s.length()))
293 m_placement = TopCenter;
294 else if (0 == strncasecmp(s.c_str(), "TopRight", s.length()))
295 m_placement = TopRight;
296 else if ( 0 == strncasecmp(s.c_str(), "BottomRight", s.length()))
297 m_placement = BottomRight;
298 else if ( 0 == strncasecmp(s.c_str(), "BottomCenter", s.length()))
299 m_placement = BottomCenter;
300 }
301
302 rname.seekp(0); rclass.seekp(0);
303 rname << rscreen.str() << "toolbar.onTop" << ends;
304 rclass << rscreen.str() << "Toolbar.OnTop" << ends;
305 if (config.getValue(rname.str(), rclass.str(), b))
306 m_ontop = b;
307
308 rname.seekp(0); rclass.seekp(0);
309 rname << rscreen.str() << "toolbar.autoHide" << ends;
310 rclass << rscreen.str() << "Toolbar.AutoHide" << ends;
311 if (config.getValue(rname.str(), rclass.str(), b))
312 m_hidden = m_autohide = b;
313 rscreen.rdbuf()->freeze(0);
314 rname.rdbuf()->freeze(0);
315 rclass.rdbuf()->freeze(0);
316 }
317
318 void Toolbar::reconfigure() {
319 frame.bevel_w = screen.getBevelWidth();
320 frame.width = screen.size().w() * m_width_percent / 100;
321
322 if (i18n->multibyte())
323 frame.height =
324 screen.getToolbarStyle()->fontset_extents->max_ink_extent.height;
325 else
326 frame.height = screen.getToolbarStyle()->font->ascent +
327 screen.getToolbarStyle()->font->descent;
328 frame.button_w = frame.height;
329 frame.height += 2;
330 frame.label_h = frame.height;
331 frame.height += (frame.bevel_w * 2);
332
333 switch (m_placement) {
334 case TopLeft:
335 frame.x = 0;
336 frame.y = 0;
337 frame.x_hidden = 0;
338 frame.y_hidden = screen.getBevelWidth() - screen.getBorderWidth()
339 - frame.height;
340 break;
341
342 case BottomLeft:
343 frame.x = 0;
344 frame.y = screen.size().h() - frame.height
345 - (screen.getBorderWidth() * 2);
346 frame.x_hidden = 0;
347 frame.y_hidden = screen.size().h() - screen.getBevelWidth()
348 - screen.getBorderWidth();
349 break;
350
351 case TopCenter:
352 frame.x = (screen.size().w() - frame.width) / 2;
353 frame.y = 0;
354 frame.x_hidden = frame.x;
355 frame.y_hidden = screen.getBevelWidth() - screen.getBorderWidth()
356 - frame.height;
357 break;
358
359 case BottomCenter:
360 default:
361 frame.x = (screen.size().w() - frame.width) / 2;
362 frame.y = screen.size().h() - frame.height
363 - (screen.getBorderWidth() * 2);
364 frame.x_hidden = frame.x;
365 frame.y_hidden = screen.size().h() - screen.getBevelWidth()
366 - screen.getBorderWidth();
367 break;
368
369 case TopRight:
370 frame.x = screen.size().w() - frame.width
371 - (screen.getBorderWidth() * 2);
372 frame.y = 0;
373 frame.x_hidden = frame.x;
374 frame.y_hidden = screen.getBevelWidth() - screen.getBorderWidth()
375 - frame.height;
376 break;
377
378 case BottomRight:
379 frame.x = screen.size().w() - frame.width
380 - (screen.getBorderWidth() * 2);
381 frame.y = screen.size().h() - frame.height
382 - (screen.getBorderWidth() * 2);
383 frame.x_hidden = frame.x;
384 frame.y_hidden = screen.size().h() - screen.getBevelWidth()
385 - screen.getBorderWidth();
386 break;
387 }
388
389 #ifdef HAVE_STRFTIME
390 time_t ttmp = time(NULL);
391 struct tm *tt = 0;
392
393 if (ttmp != -1) {
394 tt = localtime(&ttmp);
395 if (tt) {
396 char t[1025], *time_string = (char *) 0;
397 int len = strftime(t, 1024, screen.strftimeFormat(), tt);
398 t[len++-1] = ' '; // add a space to the string for padding
399 t[len] = '\0';
400
401 if (i18n->multibyte()) {
402 XRectangle ink, logical;
403 XmbTextExtents(screen.getToolbarStyle()->fontset, t, len, &ink,
404 &logical);
405 frame.clock_w = logical.width;
406
407 // ben's additional solution to pad some space beside the numbers
408 //frame.clock_w +=
409 // screen.getToolbarStyle()->fontset_extents->max_logical_extent.width *
410 // 4;
411
412 // brad's solution, which is currently buggy, too big
413 //frame.clock_w =
414 // screen.getToolbarStyle()->fontset_extents->max_logical_extent.width
415 // * len;
416 } else {
417 frame.clock_w = XTextWidth(screen.getToolbarStyle()->font, t, len);
418 // ben's additional solution to pad some space beside the numbers
419 //frame.clock_w += screen.getToolbarStyle()->font->max_bounds.width * 4;
420 // brad's solution again, too big
421 //frame.clock_w = screen.getToolbarStyle()->font->max_bounds.width * len;
422 }
423 frame.clock_w += (frame.bevel_w * 4);
424
425 delete [] time_string;
426 } else {
427 frame.clock_w = 0;
428 }
429 } else {
430 frame.clock_w = 0;
431 }
432 #else // !HAVE_STRFTIME
433 frame.clock_w =
434 XTextWidth(screen.getToolbarStyle()->font,
435 i18n->getMessage(ToolbarSet, ToolbarNoStrftimeLength,
436 "00:00000"),
437 strlen(i18n->getMessage(ToolbarSet, ToolbarNoStrftimeLength,
438 "00:00000"))) + (frame.bevel_w * 4);
439 #endif // HAVE_STRFTIME
440
441 int i;
442 unsigned int w = 0;
443 frame.workspace_label_w = 0;
444
445 for (i = 0; i < screen.getWorkspaceCount(); i++) {
446 if (i18n->multibyte()) {
447 XRectangle ink, logical;
448 XmbTextExtents(screen.getToolbarStyle()->fontset,
449 screen.getWorkspace(i)->getName(),
450 strlen(screen.getWorkspace(i)->getName()),
451 &ink, &logical);
452 w = logical.width;
453 } else {
454 w = XTextWidth(screen.getToolbarStyle()->font,
455 screen.getWorkspace(i)->getName(),
456 strlen(screen.getWorkspace(i)->getName()));
457 }
458 w += (frame.bevel_w * 4);
459
460 if (w > frame.workspace_label_w) frame.workspace_label_w = w;
461 }
462
463 if (frame.workspace_label_w < frame.clock_w)
464 frame.workspace_label_w = frame.clock_w;
465 else if (frame.workspace_label_w > frame.clock_w)
466 frame.clock_w = frame.workspace_label_w;
467
468 frame.window_label_w =
469 (frame.width - (frame.clock_w + (frame.button_w * 4) +
470 frame.workspace_label_w + (frame.bevel_w * 8) + 6));
471
472 if (m_hidden) {
473 XMoveResizeWindow(display, frame.window, frame.x_hidden, frame.y_hidden,
474 frame.width, frame.height);
475 } else {
476 XMoveResizeWindow(display, frame.window, frame.x, frame.y,
477 frame.width, frame.height);
478 }
479
480 XMoveResizeWindow(display, frame.workspace_label, frame.bevel_w,
481 frame.bevel_w, frame.workspace_label_w,
482 frame.label_h);
483 XMoveResizeWindow(display, frame.psbutton, (frame.bevel_w * 2) +
484 frame.workspace_label_w + 1, frame.bevel_w + 1,
485 frame.button_w, frame.button_w);
486 XMoveResizeWindow(display ,frame.nsbutton, (frame.bevel_w * 3) +
487 frame.workspace_label_w + frame.button_w + 2,
488 frame.bevel_w + 1, frame.button_w, frame.button_w);
489 XMoveResizeWindow(display, frame.window_label, (frame.bevel_w * 4) +
490 (frame.button_w * 2) + frame.workspace_label_w + 3,
491 frame.bevel_w, frame.window_label_w, frame.label_h);
492 XMoveResizeWindow(display, frame.pwbutton, (frame.bevel_w * 5) +
493 (frame.button_w * 2) + frame.workspace_label_w +
494 frame.window_label_w + 4, frame.bevel_w + 1,
495 frame.button_w, frame.button_w);
496 XMoveResizeWindow(display, frame.nwbutton, (frame.bevel_w * 6) +
497 (frame.button_w * 3) + frame.workspace_label_w +
498 frame.window_label_w + 5, frame.bevel_w + 1,
499 frame.button_w, frame.button_w);
500 XMoveResizeWindow(display, frame.clock, frame.width - frame.clock_w -
501 frame.bevel_w, frame.bevel_w, frame.clock_w,
502 frame.label_h);
503
504 Pixmap tmp = frame.base;
505 BTexture *texture = &(screen.getToolbarStyle()->toolbar);
506 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
507 frame.base = None;
508 XSetWindowBackground(display, frame.window,
509 texture->getColor()->getPixel());
510 } else {
511 frame.base =
512 image_ctrl->renderImage(frame.width, frame.height, texture);
513 XSetWindowBackgroundPixmap(display, frame.window, frame.base);
514 }
515 if (tmp) image_ctrl->removeImage(tmp);
516
517 tmp = frame.label;
518 texture = &(screen.getToolbarStyle()->window);
519 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
520 frame.label = None;
521 XSetWindowBackground(display, frame.window_label,
522 texture->getColor()->getPixel());
523 } else {
524 frame.label =
525 image_ctrl->renderImage(frame.window_label_w, frame.label_h, texture);
526 XSetWindowBackgroundPixmap(display, frame.window_label, frame.label);
527 }
528 if (tmp) image_ctrl->removeImage(tmp);
529
530 tmp = frame.wlabel;
531 texture = &(screen.getToolbarStyle()->label);
532 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
533 frame.wlabel = None;
534 XSetWindowBackground(display, frame.workspace_label,
535 texture->getColor()->getPixel());
536 } else {
537 frame.wlabel =
538 image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
539 XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
540 }
541 if (tmp) image_ctrl->removeImage(tmp);
542
543 tmp = frame.clk;
544 texture = &(screen.getToolbarStyle()->clock);
545 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
546 frame.clk = None;
547 XSetWindowBackground(display, frame.clock,
548 texture->getColor()->getPixel());
549 } else {
550 frame.clk =
551 image_ctrl->renderImage(frame.clock_w, frame.label_h, texture);
552 XSetWindowBackgroundPixmap(display, frame.clock, frame.clk);
553 }
554 if (tmp) image_ctrl->removeImage(tmp);
555
556 tmp = frame.button;
557 texture = &(screen.getToolbarStyle()->button);
558 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
559 frame.button = None;
560
561 frame.button_pixel = texture->getColor()->getPixel();
562 XSetWindowBackground(display, frame.psbutton, frame.button_pixel);
563 XSetWindowBackground(display, frame.nsbutton, frame.button_pixel);
564 XSetWindowBackground(display, frame.pwbutton, frame.button_pixel);
565 XSetWindowBackground(display, frame.nwbutton, frame.button_pixel);
566 } else {
567 frame.button =
568 image_ctrl->renderImage(frame.button_w, frame.button_w, texture);
569
570 XSetWindowBackgroundPixmap(display, frame.psbutton, frame.button);
571 XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.button);
572 XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.button);
573 XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.button);
574 }
575 if (tmp) image_ctrl->removeImage(tmp);
576
577 tmp = frame.pbutton;
578 texture = &(screen.getToolbarStyle()->pressed);
579 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
580 frame.pbutton = None;
581 frame.pbutton_pixel = texture->getColor()->getPixel();
582 } else {
583 frame.pbutton =
584 image_ctrl->renderImage(frame.button_w, frame.button_w, texture);
585 }
586 if (tmp) image_ctrl->removeImage(tmp);
587
588 XSetWindowBorder(display, frame.window,
589 screen.getBorderColor()->getPixel());
590 XSetWindowBorderWidth(display, frame.window, screen.getBorderWidth());
591
592 XClearWindow(display, frame.window);
593 XClearWindow(display, frame.workspace_label);
594 XClearWindow(display, frame.window_label);
595 XClearWindow(display, frame.clock);
596 XClearWindow(display, frame.psbutton);
597 XClearWindow(display, frame.nsbutton);
598 XClearWindow(display, frame.pwbutton);
599 XClearWindow(display, frame.nwbutton);
600
601 redrawWindowLabel();
602 redrawWorkspaceLabel();
603 redrawPrevWorkspaceButton();
604 redrawNextWorkspaceButton();
605 redrawPrevWindowButton();
606 redrawNextWindowButton();
607 checkClock(True);
608
609 toolbarmenu->reconfigure();
610 }
611
612
613 #ifdef HAVE_STRFTIME
614 void Toolbar::checkClock(Bool redraw) {
615 #else // !HAVE_STRFTIME
616 void Toolbar::checkClock(Bool redraw, Bool date) {
617 #endif // HAVE_STRFTIME
618 time_t tmp = 0;
619 struct tm *tt = 0;
620
621 if ((tmp = time(NULL)) != -1) {
622 if (! (tt = localtime(&tmp))) return;
623 if (tt->tm_min != frame.minute || tt->tm_hour != frame.hour) {
624 frame.hour = tt->tm_hour;
625 frame.minute = tt->tm_min;
626 XClearWindow(display, frame.clock);
627 redraw = True;
628 }
629 }
630
631 if (redraw) {
632 #ifdef HAVE_STRFTIME
633 char t[1024];
634 if (! strftime(t, 1024, screen.strftimeFormat(), tt))
635 return;
636 #else // !HAVE_STRFTIME
637 char t[9];
638 if (date) {
639 // format the date... with special consideration for y2k ;)
640 if (screen.getDateFormat() == Openbox::B_EuropeanDate)
641 sprintf(t, 18n->getMessage(ToolbarSet, ToolbarNoStrftimeDateFormatEu,
642 "%02d.%02d.%02d"),
643 tt->tm_mday, tt->tm_mon + 1,
644 (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year);
645 else
646 sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeDateFormat,
647 "%02d/%02d/%02d"),
648 tt->tm_mon + 1, tt->tm_mday,
649 (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year);
650 } else {
651 if (screen.isClock24Hour())
652 sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeTimeFormat24,
653 " %02d:%02d "),
654 frame.hour, frame.minute);
655 else
656 sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeTimeFormat12,
657 "%02d:%02d %sm"),
658 ((frame.hour > 12) ? frame.hour - 12 :
659 ((frame.hour == 0) ? 12 : frame.hour)), frame.minute,
660 ((frame.hour >= 12) ?
661 i18n->getMessage(ToolbarSet,
662 ToolbarNoStrftimeTimeFormatP, "p") :
663 i18n->getMessage(ToolbarSet,
664 ToolbarNoStrftimeTimeFormatA, "a")));
665 }
666 #endif // HAVE_STRFTIME
667
668 int dx = (frame.bevel_w * 2), dlen = strlen(t);
669 unsigned int l;
670
671 if (i18n->multibyte()) {
672 XRectangle ink, logical;
673 XmbTextExtents(screen.getToolbarStyle()->fontset,
674 t, dlen, &ink, &logical);
675 l = logical.width;
676 } else {
677 l = XTextWidth(screen.getToolbarStyle()->font, t, dlen);
678 }
679
680 l += (frame.bevel_w * 4);
681
682 if (l > frame.clock_w) {
683 for (; dlen >= 0; dlen--) {
684 if (i18n->multibyte()) {
685 XRectangle ink, logical;
686 XmbTextExtents(screen.getToolbarStyle()->fontset,
687 t, dlen, &ink, &logical);
688 l = logical.width;
689 } else {
690 l = XTextWidth(screen.getToolbarStyle()->font, t, dlen);
691 }
692 l+= (frame.bevel_w * 4);
693
694 if (l < frame.clock_w)
695 break;
696 }
697 }
698 switch (screen.getToolbarStyle()->justify) {
699 case BScreen::RightJustify:
700 dx += frame.clock_w - l;
701 break;
702
703 case BScreen::CenterJustify:
704 dx += (frame.clock_w - l) / 2;
705 break;
706 }
707
708 ToolbarStyle *style = screen.getToolbarStyle();
709 if (i18n->multibyte())
710 XmbDrawString(display, frame.clock, style->fontset, style->c_text_gc,
711 dx, (1 - style->fontset_extents->max_ink_extent.y),
712 t, dlen);
713 else
714 XDrawString(display, frame.clock, style->c_text_gc, dx,
715 (style->font->ascent + 1), t, dlen);
716 }
717 }
718
719
720 void Toolbar::redrawWindowLabel(Bool redraw) {
721 if (screen.getOpenbox().getFocusedWindow()) {
722 if (redraw)
723 XClearWindow(display, frame.window_label);
724
725 OpenboxWindow *foc = screen.getOpenbox().getFocusedWindow();
726 if (foc->getScreen() != &screen) return;
727
728 int dx = (frame.bevel_w * 2), dlen = strlen(*foc->getTitle());
729 unsigned int l;
730
731 if (i18n->multibyte()) {
732 XRectangle ink, logical;
733 XmbTextExtents(screen.getToolbarStyle()->fontset, *foc->getTitle(),
734 dlen, &ink, &logical);
735 l = logical.width;
736 } else {
737 l = XTextWidth(screen.getToolbarStyle()->font, *foc->getTitle(), dlen);
738 }
739 l += (frame.bevel_w * 4);
740
741 if (l > frame.window_label_w) {
742 for (; dlen >= 0; dlen--) {
743 if (i18n->multibyte()) {
744 XRectangle ink, logical;
745 XmbTextExtents(screen.getToolbarStyle()->fontset,
746 *foc->getTitle(), dlen, &ink, &logical);
747 l = logical.width;
748 } else {
749 l = XTextWidth(screen.getToolbarStyle()->font,
750 *foc->getTitle(), dlen);
751 }
752 l += (frame.bevel_w * 4);
753
754 if (l < frame.window_label_w)
755 break;
756 }
757 }
758 switch (screen.getToolbarStyle()->justify) {
759 case BScreen::RightJustify:
760 dx += frame.window_label_w - l;
761 break;
762
763 case BScreen::CenterJustify:
764 dx += (frame.window_label_w - l) / 2;
765 break;
766 }
767
768 ToolbarStyle *style = screen.getToolbarStyle();
769 if (i18n->multibyte())
770 XmbDrawString(display, frame.window_label, style->fontset,
771 style->w_text_gc, dx,
772 (1 - style->fontset_extents->max_ink_extent.y),
773 *foc->getTitle(), dlen);
774 else
775 XDrawString(display, frame.window_label, style->w_text_gc, dx,
776 (style->font->ascent + 1), *foc->getTitle(), dlen);
777 } else {
778 XClearWindow(display, frame.window_label);
779 }
780 }
781
782
783 void Toolbar::redrawWorkspaceLabel(Bool redraw) {
784 if (screen.getCurrentWorkspace()->getName()) {
785 if (redraw)
786 XClearWindow(display, frame.workspace_label);
787
788 int dx = (frame.bevel_w * 2), dlen =
789 strlen(screen.getCurrentWorkspace()->getName());
790 unsigned int l;
791
792 if (i18n->multibyte()) {
793 XRectangle ink, logical;
794 XmbTextExtents(screen.getToolbarStyle()->fontset,
795 screen.getCurrentWorkspace()->getName(), dlen,
796 &ink, &logical);
797 l = logical.width;
798 } else {
799 l = XTextWidth(screen.getToolbarStyle()->font,
800 screen.getCurrentWorkspace()->getName(), dlen);
801 }
802 l += (frame.bevel_w * 4);
803
804 if (l > frame.workspace_label_w) {
805 for (; dlen >= 0; dlen--) {
806 if (i18n->multibyte()) {
807 XRectangle ink, logical;
808 XmbTextExtents(screen.getToolbarStyle()->fontset,
809 screen.getCurrentWorkspace()->getName(), dlen,
810 &ink, &logical);
811 l = logical.width;
812 } else {
813 l = XTextWidth(screen.getWindowStyle()->font,
814 screen.getCurrentWorkspace()->getName(), dlen);
815 }
816 l += (frame.bevel_w * 4);
817
818 if (l < frame.workspace_label_w)
819 break;
820 }
821 }
822 switch (screen.getToolbarStyle()->justify) {
823 case BScreen::RightJustify:
824 dx += frame.workspace_label_w - l;
825 break;
826
827 case BScreen::CenterJustify:
828 dx += (frame.workspace_label_w - l) / 2;
829 break;
830 }
831
832 ToolbarStyle *style = screen.getToolbarStyle();
833 if (i18n->multibyte())
834 XmbDrawString(display, frame.workspace_label, style->fontset,
835 style->l_text_gc, dx,
836 (1 - style->fontset_extents->max_ink_extent.y),
837 (char *) screen.getCurrentWorkspace()->getName(), dlen);
838 else
839 XDrawString(display, frame.workspace_label, style->l_text_gc, dx,
840 (style->font->ascent + 1),
841 (char *) screen.getCurrentWorkspace()->getName(), dlen);
842 }
843 }
844
845
846 void Toolbar::redrawPrevWorkspaceButton(Bool pressed, Bool redraw) {
847 if (redraw) {
848 if (pressed) {
849 if (frame.pbutton)
850 XSetWindowBackgroundPixmap(display, frame.psbutton, frame.pbutton);
851 else
852 XSetWindowBackground(display, frame.psbutton, frame.pbutton_pixel);
853 } else {
854 if (frame.button)
855 XSetWindowBackgroundPixmap(display, frame.psbutton, frame.button);
856 else
857 XSetWindowBackground(display, frame.psbutton, frame.button_pixel);
858 }
859 XClearWindow(display, frame.psbutton);
860 }
861
862 int hh = frame.button_w / 2, hw = frame.button_w / 2;
863
864 XPoint pts[3];
865 pts[0].x = hw - 2; pts[0].y = hh;
866 pts[1].x = 4; pts[1].y = 2;
867 pts[2].x = 0; pts[2].y = -4;
868
869 XFillPolygon(display, frame.psbutton, screen.getToolbarStyle()->b_pic_gc,
870 pts, 3, Convex, CoordModePrevious);
871 }
872
873
874 void Toolbar::redrawNextWorkspaceButton(Bool pressed, Bool redraw) {
875 if (redraw) {
876 if (pressed) {
877 if (frame.pbutton)
878 XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.pbutton);
879 else
880 XSetWindowBackground(display, frame.nsbutton, frame.pbutton_pixel);
881 } else {
882 if (frame.button)
883 XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.button);
884 else
885 XSetWindowBackground(display, frame.nsbutton, frame.button_pixel);
886 }
887 XClearWindow(display, frame.nsbutton);
888 }
889
890 int hh = frame.button_w / 2, hw = frame.button_w / 2;
891
892 XPoint pts[3];
893 pts[0].x = hw - 2; pts[0].y = hh - 2;
894 pts[1].x = 4; pts[1].y = 2;
895 pts[2].x = -4; pts[2].y = 2;
896
897 XFillPolygon(display, frame.nsbutton, screen.getToolbarStyle()->b_pic_gc,
898 pts, 3, Convex, CoordModePrevious);
899 }
900
901
902 void Toolbar::redrawPrevWindowButton(Bool pressed, Bool redraw) {
903 if (redraw) {
904 if (pressed) {
905 if (frame.pbutton)
906 XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.pbutton);
907 else
908 XSetWindowBackground(display, frame.pwbutton, frame.pbutton_pixel);
909 } else {
910 if (frame.button)
911 XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.button);
912 else
913 XSetWindowBackground(display, frame.pwbutton, frame.button_pixel);
914 }
915 XClearWindow(display, frame.pwbutton);
916 }
917
918 int hh = frame.button_w / 2, hw = frame.button_w / 2;
919
920 XPoint pts[3];
921 pts[0].x = hw - 2; pts[0].y = hh;
922 pts[1].x = 4; pts[1].y = 2;
923 pts[2].x = 0; pts[2].y = -4;
924
925 XFillPolygon(display, frame.pwbutton, screen.getToolbarStyle()->b_pic_gc,
926 pts, 3, Convex, CoordModePrevious);
927 }
928
929
930 void Toolbar::redrawNextWindowButton(Bool pressed, Bool redraw) {
931 if (redraw) {
932 if (pressed) {
933 if (frame.pbutton)
934 XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.pbutton);
935 else
936 XSetWindowBackground(display, frame.nwbutton, frame.pbutton_pixel);
937 } else {
938 if (frame.button)
939 XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.button);
940 else
941 XSetWindowBackground(display, frame.nwbutton, frame.button_pixel);
942 }
943 XClearWindow(display, frame.nwbutton);
944 }
945
946 int hh = frame.button_w / 2, hw = frame.button_w / 2;
947
948 XPoint pts[3];
949 pts[0].x = hw - 2; pts[0].y = hh - 2;
950 pts[1].x = 4; pts[1].y = 2;
951 pts[2].x = -4; pts[2].y = 2;
952
953 XFillPolygon(display, frame.nwbutton, screen.getToolbarStyle()->b_pic_gc,
954 pts, 3, Convex, CoordModePrevious);
955 }
956
957
958 void Toolbar::edit() {
959 Window window;
960 int foo;
961
962 m_editing = True;
963 if (XGetInputFocus(display, &window, &foo) &&
964 window == frame.workspace_label)
965 return;
966
967 XSetInputFocus(display, frame.workspace_label,
968 ((screen.sloppyFocus()) ? RevertToPointerRoot :
969 RevertToParent),
970 CurrentTime);
971 XClearWindow(display, frame.workspace_label);
972
973 openbox.setNoFocus(True);
974 if (openbox.getFocusedWindow())
975 openbox.getFocusedWindow()->setFocusFlag(False);
976
977 XDrawRectangle(display, frame.workspace_label,
978 screen.getWindowStyle()->l_text_focus_gc,
979 frame.workspace_label_w / 2, 0, 1,
980 frame.label_h - 1);
981
982 // change the background of the window to that of an active window label
983 Pixmap tmp = frame.wlabel;
984 BTexture *texture = &(screen.getWindowStyle()->l_focus);
985 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
986 frame.wlabel = None;
987 XSetWindowBackground(display, frame.workspace_label,
988 texture->getColor()->getPixel());
989 } else {
990 frame.wlabel =
991 image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
992 XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
993 }
994 if (tmp) image_ctrl->removeImage(tmp);
995 }
996
997
998 void Toolbar::buttonPressEvent(XButtonEvent *be) {
999 if (be->button == 1) {
1000 if (be->window == frame.psbutton)
1001 redrawPrevWorkspaceButton(True, True);
1002 else if (be->window == frame.nsbutton)
1003 redrawNextWorkspaceButton(True, True);
1004 else if (be->window == frame.pwbutton)
1005 redrawPrevWindowButton(True, True);
1006 else if (be->window == frame.nwbutton)
1007 redrawNextWindowButton(True, True);
1008 #ifndef HAVE_STRFTIME
1009 else if (be->window == frame.clock) {
1010 XClearWindow(display, frame.clock);
1011 checkClock(True, True);
1012 }
1013 #endif // HAVE_STRFTIME
1014 else if (! m_ontop) {
1015 Window w[1] = { frame.window };
1016 screen.raiseWindows(w, 1);
1017 }
1018 } else if (be->button == 2 && (! m_ontop)) {
1019 XLowerWindow(display, frame.window);
1020 } else if (be->button == 3) {
1021 if (! toolbarmenu->isVisible()) {
1022 int x, y;
1023
1024 x = be->x_root - (toolbarmenu->getWidth() / 2);
1025 y = be->y_root - (toolbarmenu->getHeight() / 2);
1026
1027 if (x < 0)
1028 x = 0;
1029 else if (x + toolbarmenu->getWidth() > screen.size().w())
1030 x = screen.size().w() - toolbarmenu->getWidth();
1031
1032 if (y < 0)
1033 y = 0;
1034 else if (y + toolbarmenu->getHeight() > screen.size().h())
1035 y = screen.size().h() - toolbarmenu->getHeight();
1036
1037 toolbarmenu->move(x, y);
1038 toolbarmenu->show();
1039 } else
1040 toolbarmenu->hide();
1041 }
1042 }
1043
1044
1045
1046 void Toolbar::buttonReleaseEvent(XButtonEvent *re) {
1047 if (re->button == 1) {
1048 if (re->window == frame.psbutton) {
1049 redrawPrevWorkspaceButton(False, True);
1050
1051 if (re->x >= 0 && re->x < (signed) frame.button_w &&
1052 re->y >= 0 && re->y < (signed) frame.button_w)
1053 if (screen.getCurrentWorkspace()->getWorkspaceID() > 0)
1054 screen.changeWorkspaceID(screen.getCurrentWorkspace()->
1055 getWorkspaceID() - 1);
1056 else
1057 screen.changeWorkspaceID(screen.getWorkspaceCount() - 1);
1058 } else if (re->window == frame.nsbutton) {
1059 redrawNextWorkspaceButton(False, True);
1060
1061 if (re->x >= 0 && re->x < (signed) frame.button_w &&
1062 re->y >= 0 && re->y < (signed) frame.button_w)
1063 if (screen.getCurrentWorkspace()->getWorkspaceID() <
1064 screen.getWorkspaceCount() - 1)
1065 screen.changeWorkspaceID(screen.getCurrentWorkspace()->
1066 getWorkspaceID() + 1);
1067 else
1068 screen.changeWorkspaceID(0);
1069 } else if (re->window == frame.pwbutton) {
1070 redrawPrevWindowButton(False, True);
1071
1072 if (re->x >= 0 && re->x < (signed) frame.button_w &&
1073 re->y >= 0 && re->y < (signed) frame.button_w)
1074 screen.prevFocus();
1075 } else if (re->window == frame.nwbutton) {
1076 redrawNextWindowButton(False, True);
1077
1078 if (re->x >= 0 && re->x < (signed) frame.button_w &&
1079 re->y >= 0 && re->y < (signed) frame.button_w)
1080 screen.nextFocus();
1081 } else if (re->window == frame.window_label)
1082 screen.raiseFocus();
1083 #ifndef HAVE_STRFTIME
1084 else if (re->window == frame.clock) {
1085 XClearWindow(display, frame.clock);
1086 checkClock(True);
1087 }
1088 #endif // HAVE_STRFTIME
1089 }
1090 }
1091
1092
1093 void Toolbar::enterNotifyEvent(XCrossingEvent *) {
1094 if (! m_autohide)
1095 return;
1096
1097 if (m_hidden) {
1098 if (! hide_timer->isTiming()) hide_timer->start();
1099 } else {
1100 if (hide_timer->isTiming()) hide_timer->stop();
1101 }
1102 }
1103
1104 void Toolbar::leaveNotifyEvent(XCrossingEvent *) {
1105 if (! m_autohide)
1106 return;
1107
1108 if (m_hidden) {
1109 if (hide_timer->isTiming()) hide_timer->stop();
1110 } else if (! toolbarmenu->isVisible()) {
1111 if (! hide_timer->isTiming()) hide_timer->start();
1112 }
1113 }
1114
1115
1116 void Toolbar::exposeEvent(XExposeEvent *ee) {
1117 if (ee->window == frame.clock) checkClock(True);
1118 else if (ee->window == frame.workspace_label && (! m_editing))
1119 redrawWorkspaceLabel();
1120 else if (ee->window == frame.window_label) redrawWindowLabel();
1121 else if (ee->window == frame.psbutton) redrawPrevWorkspaceButton();
1122 else if (ee->window == frame.nsbutton) redrawNextWorkspaceButton();
1123 else if (ee->window == frame.pwbutton) redrawPrevWindowButton();
1124 else if (ee->window == frame.nwbutton) redrawNextWindowButton();
1125 }
1126
1127
1128 void Toolbar::keyPressEvent(XKeyEvent *ke) {
1129 if (ke->window == frame.workspace_label && m_editing) {
1130 openbox.grab();
1131
1132 if (! new_workspace_name) {
1133 new_workspace_name = new char[128];
1134 new_name_pos = 0;
1135
1136 if (! new_workspace_name) return;
1137 }
1138
1139 KeySym ks;
1140 char keychar[1];
1141 XLookupString(ke, keychar, 1, &ks, 0);
1142
1143 // either we are told to end with a return or we hit the end of the buffer
1144 if (ks == XK_Return || new_name_pos == 127) {
1145 *(new_workspace_name + new_name_pos) = 0;
1146
1147 m_editing = False;
1148
1149 openbox.setNoFocus(False);
1150 if (openbox.getFocusedWindow()) {
1151 openbox.getFocusedWindow()->setInputFocus();
1152 openbox.getFocusedWindow()->setFocusFlag(True);
1153 } else {
1154 XSetInputFocus(display, PointerRoot, None, CurrentTime);
1155 }
1156 // check to make sure that new_name[0] != 0... otherwise we have a null
1157 // workspace name which causes serious problems, especially for the
1158 // Openbox::LoadRC() method.
1159 if (*new_workspace_name) {
1160 screen.getCurrentWorkspace()->setName(new_workspace_name);
1161 screen.getCurrentWorkspace()->getMenu()->hide();
1162 screen.getWorkspacemenu()->
1163 remove(screen.getCurrentWorkspace()->getWorkspaceID() + 2);
1164 screen.getWorkspacemenu()->
1165 insert(screen.getCurrentWorkspace()->getName(),
1166 screen.getCurrentWorkspace()->getMenu(),
1167 screen.getCurrentWorkspace()->getWorkspaceID() + 2);
1168 screen.getWorkspacemenu()->update();
1169 }
1170
1171 delete [] new_workspace_name;
1172 new_workspace_name = (char *) 0;
1173 new_name_pos = 0;
1174
1175 // reset the background to that of the workspace label (its normal
1176 // setting)
1177 Pixmap tmp = frame.wlabel;
1178 BTexture *texture = &(screen.getToolbarStyle()->label);
1179 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
1180 frame.wlabel = None;
1181 XSetWindowBackground(display, frame.workspace_label,
1182 texture->getColor()->getPixel());
1183 } else {
1184 frame.wlabel =
1185 image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
1186 XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
1187 }
1188 if (tmp) image_ctrl->removeImage(tmp);
1189
1190 reconfigure();
1191 } else if (! (ks == XK_Shift_L || ks == XK_Shift_R ||
1192 ks == XK_Control_L || ks == XK_Control_R ||
1193 ks == XK_Caps_Lock || ks == XK_Shift_Lock ||
1194 ks == XK_Meta_L || ks == XK_Meta_R ||
1195 ks == XK_Alt_L || ks == XK_Alt_R ||
1196 ks == XK_Super_L || ks == XK_Super_R ||
1197 ks == XK_Hyper_L || ks == XK_Hyper_R)) {
1198 if (ks == XK_BackSpace) {
1199 if (new_name_pos > 0) {
1200 --new_name_pos;
1201 *(new_workspace_name + new_name_pos) = '\0';
1202 } else {
1203 *new_workspace_name = '\0';
1204 }
1205 } else {
1206 *(new_workspace_name + new_name_pos) = *keychar;
1207 ++new_name_pos;
1208 *(new_workspace_name + new_name_pos) = '\0';
1209 }
1210
1211 XClearWindow(display, frame.workspace_label);
1212 int l = strlen(new_workspace_name), tw, x;
1213
1214 if (i18n->multibyte()) {
1215 XRectangle ink, logical;
1216 XmbTextExtents(screen.getToolbarStyle()->fontset,
1217 new_workspace_name, l, &ink, &logical);
1218 tw = logical.width;
1219 } else {
1220 tw = XTextWidth(screen.getToolbarStyle()->font,
1221 new_workspace_name, l);
1222 }
1223 x = (frame.workspace_label_w - tw) / 2;
1224
1225 if (x < (signed) frame.bevel_w) x = frame.bevel_w;
1226
1227 WindowStyle *style = screen.getWindowStyle();
1228 if (i18n->multibyte())
1229 XmbDrawString(display, frame.workspace_label, style->fontset,
1230 style->l_text_focus_gc, x,
1231 (1 - style->fontset_extents->max_ink_extent.y),
1232 new_workspace_name, l);
1233 else
1234 XDrawString(display, frame.workspace_label, style->l_text_focus_gc, x,
1235 (style->font->ascent + 1),
1236 new_workspace_name, l);
1237
1238 XDrawRectangle(display, frame.workspace_label,
1239 screen.getWindowStyle()->l_text_focus_gc, x + tw, 0, 1,
1240 frame.label_h - 1);
1241 }
1242
1243 openbox.ungrab();
1244 }
1245 }
1246
1247
1248 void Toolbar::timeout() {
1249 checkClock(True);
1250
1251 timeval now;
1252 gettimeofday(&now, 0);
1253 clock_timer->setTimeout((60 - (now.tv_sec % 60)) * 1000);
1254 }
1255
1256
1257 void Toolbar::HideHandler::timeout() {
1258 toolbar->m_hidden = !toolbar->m_hidden;
1259 if (toolbar->m_hidden)
1260 XMoveWindow(toolbar->display, toolbar->frame.window,
1261 toolbar->frame.x_hidden, toolbar->frame.y_hidden);
1262 else
1263 XMoveWindow(toolbar->display, toolbar->frame.window,
1264 toolbar->frame.x, toolbar->frame.y);
1265 }
1266
1267
1268 Toolbarmenu::Toolbarmenu(Toolbar &tb) : Basemenu(tb.screen), toolbar(tb) {
1269 setLabel(i18n->getMessage(ToolbarSet, ToolbarToolbarTitle, "Toolbar"));
1270 setInternalMenu();
1271
1272 placementmenu = new Placementmenu(*this);
1273
1274 insert(i18n->getMessage(CommonSet, CommonPlacementTitle, "Placement"),
1275 placementmenu);
1276 insert(i18n->getMessage(CommonSet, CommonAlwaysOnTop, "Always on top"), 1);
1277 insert(i18n->getMessage(CommonSet, CommonAutoHide, "Auto hide"), 2);
1278 insert(i18n->getMessage(ToolbarSet, ToolbarEditWkspcName,
1279 "Edit current workspace name"), 3);
1280
1281 update();
1282
1283 setValues();
1284 }
1285
1286 void Toolbarmenu::setValues() {
1287 setItemSelected(1, toolbar.onTop());
1288 setItemSelected(2, toolbar.autoHide());
1289 }
1290
1291
1292 Toolbarmenu::~Toolbarmenu() {
1293 delete placementmenu;
1294 }
1295
1296
1297 void Toolbarmenu::itemSelected(int button, int index) {
1298 if (button != 1)
1299 return;
1300
1301 BasemenuItem *item = find(index);
1302 if (! item) return;
1303
1304 switch (item->function()) {
1305 case 1: { // always on top
1306 Bool change = ((toolbar.onTop()) ? False : True);
1307 toolbar.setOnTop(change);
1308 setItemSelected(1, change);
1309
1310 if (toolbar.onTop()) toolbar.screen.raiseWindows((Window *) 0, 0);
1311 break;
1312 }
1313
1314 case 2: { // auto hide
1315 Bool change = ((toolbar.autoHide()) ? False : True);
1316 toolbar.setAutoHide(change);
1317 setItemSelected(2, change);
1318
1319 #ifdef SLIT
1320 toolbar.screen.getSlit()->reposition();
1321 #endif // SLIT
1322 break;
1323 }
1324
1325 case 3: { // edit current workspace name
1326 toolbar.edit();
1327 hide();
1328
1329 break;
1330 }
1331 } // switch
1332 }
1333
1334
1335 void Toolbarmenu::internal_hide() {
1336 Basemenu::internal_hide();
1337 if (toolbar.autoHide() && ! toolbar.isEditing())
1338 toolbar.hide_handler.timeout();
1339 }
1340
1341
1342 void Toolbarmenu::reconfigure() {
1343 setValues();
1344 placementmenu->reconfigure();
1345
1346 Basemenu::reconfigure();
1347 }
1348
1349
1350 Toolbarmenu::Placementmenu::Placementmenu(Toolbarmenu &tm)
1351 : Basemenu(tm.toolbar.screen), toolbarmenu(tm) {
1352 setLabel(i18n->getMessage(ToolbarSet, ToolbarToolbarPlacement,
1353 "Toolbar Placement"));
1354 setInternalMenu();
1355 setMinimumSublevels(3);
1356
1357 insert(i18n->getMessage(CommonSet, CommonPlacementTopLeft,
1358 "Top Left"), Toolbar::TopLeft);
1359 insert(i18n->getMessage(CommonSet, CommonPlacementBottomLeft,
1360 "Bottom Left"), Toolbar::BottomLeft);
1361 insert(i18n->getMessage(CommonSet, CommonPlacementTopCenter,
1362 "Top Center"), Toolbar::TopCenter);
1363 insert(i18n->getMessage(CommonSet, CommonPlacementBottomCenter,
1364 "Bottom Center"), Toolbar::BottomCenter);
1365 insert(i18n->getMessage(CommonSet, CommonPlacementTopRight,
1366 "Top Right"), Toolbar::TopRight);
1367 insert(i18n->getMessage(CommonSet, CommonPlacementBottomRight,
1368 "Bottom Right"), Toolbar::BottomRight);
1369 update();
1370 }
1371
1372 void Toolbarmenu::Placementmenu::itemSelected(int button, int index) {
1373 if (button != 1)
1374 return;
1375
1376 BasemenuItem *item = find(index);
1377 if (! item) return;
1378
1379 toolbarmenu.toolbar.setPlacement(item->function());
1380 hide();
1381 toolbarmenu.toolbar.reconfigure();
1382
1383 #ifdef SLIT
1384 // reposition the slit as well to make sure it doesn't intersect the
1385 // toolbar
1386 toolbarmenu.toolbar.screen.getSlit()->reposition();
1387 #endif // SLIT
1388 }
This page took 0.096847 seconds and 5 git commands to generate.