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