]> Dogcows Code - chaz/openbox/blob - src/Toolbar.cc
*** empty log message ***
[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 std::ends;
68
69 Toolbar::Toolbar(BScreen &scrn, Resource &conf) : openbox(scrn.getOpenbox()),
70 screen(scrn), 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 std::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 std::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 std::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 std::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 std::ostrstream rscreen, rname, rclass;
269 std::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.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
283 rname << rscreen.str() << "toolbar.placement" << ends;
284 rclass << rscreen.str() << "Toolbar.Placement" << ends;
285 if (config.getValue(rname.str(), rclass.str(), s)) {
286 if (0 == strncasecmp(s.c_str(), "TopLeft", s.length()))
287 m_placement = TopLeft;
288 else if (0 == strncasecmp(s.c_str(), "BottomLeft", s.length()))
289 m_placement = BottomLeft;
290 else if (0 == strncasecmp(s.c_str(), "TopCenter", s.length()))
291 m_placement = TopCenter;
292 else if (0 == strncasecmp(s.c_str(), "TopRight", s.length()))
293 m_placement = TopRight;
294 else if ( 0 == strncasecmp(s.c_str(), "BottomRight", s.length()))
295 m_placement = BottomRight;
296 else if ( 0 == strncasecmp(s.c_str(), "BottomCenter", s.length()))
297 m_placement = BottomCenter;
298 } else
299 m_placement = BottomCenter;
300
301 rname.seekp(0); rclass.seekp(0);
302 rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(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 else
308 m_ontop = false;
309
310 rname.seekp(0); rclass.seekp(0);
311 rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
312 rname << rscreen.str() << "toolbar.autoHide" << ends;
313 rclass << rscreen.str() << "Toolbar.AutoHide" << ends;
314 if (config.getValue(rname.str(), rclass.str(), b))
315 m_hidden = m_autohide = b;
316 else
317 m_hidden = m_autohide = false;
318
319 rscreen.rdbuf()->freeze(0);
320 rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
321 }
322
323 void Toolbar::reconfigure() {
324 frame.bevel_w = screen.getBevelWidth();
325 frame.width = screen.size().w() * m_width_percent / 100;
326
327 if (i18n->multibyte())
328 frame.height =
329 screen.getToolbarStyle()->fontset_extents->max_ink_extent.height;
330 else
331 frame.height = screen.getToolbarStyle()->font->ascent +
332 screen.getToolbarStyle()->font->descent;
333 frame.button_w = frame.height;
334 frame.height += 2;
335 frame.label_h = frame.height;
336 frame.height += (frame.bevel_w * 2);
337
338 switch (m_placement) {
339 case TopLeft:
340 frame.x = 0;
341 frame.y = 0;
342 frame.x_hidden = 0;
343 frame.y_hidden = screen.getBevelWidth() - screen.getBorderWidth()
344 - frame.height;
345 break;
346
347 case BottomLeft:
348 frame.x = 0;
349 frame.y = screen.size().h() - frame.height
350 - (screen.getBorderWidth() * 2);
351 frame.x_hidden = 0;
352 frame.y_hidden = screen.size().h() - screen.getBevelWidth()
353 - screen.getBorderWidth();
354 break;
355
356 case TopCenter:
357 frame.x = (screen.size().w() - frame.width) / 2;
358 frame.y = 0;
359 frame.x_hidden = frame.x;
360 frame.y_hidden = screen.getBevelWidth() - screen.getBorderWidth()
361 - frame.height;
362 break;
363
364 case BottomCenter:
365 default:
366 frame.x = (screen.size().w() - frame.width) / 2;
367 frame.y = screen.size().h() - frame.height
368 - (screen.getBorderWidth() * 2);
369 frame.x_hidden = frame.x;
370 frame.y_hidden = screen.size().h() - screen.getBevelWidth()
371 - screen.getBorderWidth();
372 break;
373
374 case TopRight:
375 frame.x = screen.size().w() - frame.width
376 - (screen.getBorderWidth() * 2);
377 frame.y = 0;
378 frame.x_hidden = frame.x;
379 frame.y_hidden = screen.getBevelWidth() - screen.getBorderWidth()
380 - frame.height;
381 break;
382
383 case BottomRight:
384 frame.x = screen.size().w() - frame.width
385 - (screen.getBorderWidth() * 2);
386 frame.y = screen.size().h() - frame.height
387 - (screen.getBorderWidth() * 2);
388 frame.x_hidden = frame.x;
389 frame.y_hidden = screen.size().h() - screen.getBevelWidth()
390 - screen.getBorderWidth();
391 break;
392 }
393
394 #ifdef HAVE_STRFTIME
395 time_t ttmp = time(NULL);
396 struct tm *tt = 0;
397
398 if (ttmp != -1) {
399 tt = localtime(&ttmp);
400 if (tt) {
401 char t[1025], *time_string = (char *) 0;
402 int len = strftime(t, 1024, screen.strftimeFormat(), tt);
403 t[len++] = 'A'; // add size to the string for padding
404 t[len++] = 'A'; // add size to the string for padding
405 t[len] = '\0';
406
407 if (i18n->multibyte()) {
408 XRectangle ink, logical;
409 XmbTextExtents(screen.getToolbarStyle()->fontset, t, len, &ink,
410 &logical);
411 frame.clock_w = logical.width;
412
413 // ben's additional solution to pad some space beside the numbers
414 //frame.clock_w +=
415 // screen.getToolbarStyle()->fontset_extents->max_logical_extent.width *
416 // 4;
417
418 // brad's solution, which is currently buggy, too big
419 //frame.clock_w =
420 // screen.getToolbarStyle()->fontset_extents->max_logical_extent.width
421 // * len;
422 } else {
423 frame.clock_w = XTextWidth(screen.getToolbarStyle()->font, t, len);
424 // ben's additional solution to pad some space beside the numbers
425 //frame.clock_w += screen.getToolbarStyle()->font->max_bounds.width * 4;
426 // brad's solution again, too big
427 //frame.clock_w = screen.getToolbarStyle()->font->max_bounds.width * len;
428 }
429 frame.clock_w += (frame.bevel_w * 4);
430
431 delete [] time_string;
432 } else {
433 frame.clock_w = 0;
434 }
435 } else {
436 frame.clock_w = 0;
437 }
438 #else // !HAVE_STRFTIME
439 frame.clock_w =
440 XTextWidth(screen.getToolbarStyle()->font,
441 i18n->getMessage(ToolbarSet, ToolbarNoStrftimeLength,
442 "00:00000"),
443 strlen(i18n->getMessage(ToolbarSet, ToolbarNoStrftimeLength,
444 "00:00000"))) + (frame.bevel_w * 4);
445 #endif // HAVE_STRFTIME
446
447 int i;
448 unsigned int w = 0;
449 frame.workspace_label_w = 0;
450
451 for (i = 0; i < screen.getWorkspaceCount(); i++) {
452 if (i18n->multibyte()) {
453 XRectangle ink, logical;
454 XmbTextExtents(screen.getToolbarStyle()->fontset,
455 screen.getWorkspace(i)->getName(),
456 strlen(screen.getWorkspace(i)->getName()),
457 &ink, &logical);
458 w = logical.width;
459 } else {
460 w = XTextWidth(screen.getToolbarStyle()->font,
461 screen.getWorkspace(i)->getName(),
462 strlen(screen.getWorkspace(i)->getName()));
463 }
464 w += (frame.bevel_w * 4);
465
466 if (w > frame.workspace_label_w) frame.workspace_label_w = w;
467 }
468
469 if (frame.workspace_label_w < frame.clock_w)
470 frame.workspace_label_w = frame.clock_w;
471 else if (frame.workspace_label_w > frame.clock_w)
472 frame.clock_w = frame.workspace_label_w;
473
474 frame.window_label_w =
475 (frame.width - (frame.clock_w + (frame.button_w * 4) +
476 frame.workspace_label_w + (frame.bevel_w * 8) + 6));
477
478 if (m_hidden) {
479 XMoveResizeWindow(display, frame.window, frame.x_hidden, frame.y_hidden,
480 frame.width, frame.height);
481 } else {
482 XMoveResizeWindow(display, frame.window, frame.x, frame.y,
483 frame.width, frame.height);
484 }
485
486 XMoveResizeWindow(display, frame.workspace_label, frame.bevel_w,
487 frame.bevel_w, frame.workspace_label_w,
488 frame.label_h);
489 XMoveResizeWindow(display, frame.psbutton, (frame.bevel_w * 2) +
490 frame.workspace_label_w + 1, frame.bevel_w + 1,
491 frame.button_w, frame.button_w);
492 XMoveResizeWindow(display ,frame.nsbutton, (frame.bevel_w * 3) +
493 frame.workspace_label_w + frame.button_w + 2,
494 frame.bevel_w + 1, frame.button_w, frame.button_w);
495 XMoveResizeWindow(display, frame.window_label, (frame.bevel_w * 4) +
496 (frame.button_w * 2) + frame.workspace_label_w + 3,
497 frame.bevel_w, frame.window_label_w, frame.label_h);
498 XMoveResizeWindow(display, frame.pwbutton, (frame.bevel_w * 5) +
499 (frame.button_w * 2) + frame.workspace_label_w +
500 frame.window_label_w + 4, frame.bevel_w + 1,
501 frame.button_w, frame.button_w);
502 XMoveResizeWindow(display, frame.nwbutton, (frame.bevel_w * 6) +
503 (frame.button_w * 3) + frame.workspace_label_w +
504 frame.window_label_w + 5, frame.bevel_w + 1,
505 frame.button_w, frame.button_w);
506 XMoveResizeWindow(display, frame.clock, frame.width - frame.clock_w -
507 frame.bevel_w, frame.bevel_w, frame.clock_w,
508 frame.label_h);
509
510 Pixmap tmp = frame.base;
511 BTexture *texture = &(screen.getToolbarStyle()->toolbar);
512 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
513 frame.base = None;
514 XSetWindowBackground(display, frame.window,
515 texture->getColor()->getPixel());
516 } else {
517 frame.base =
518 image_ctrl->renderImage(frame.width, frame.height, texture);
519 XSetWindowBackgroundPixmap(display, frame.window, frame.base);
520 }
521 if (tmp) image_ctrl->removeImage(tmp);
522
523 tmp = frame.label;
524 texture = &(screen.getToolbarStyle()->window);
525 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
526 frame.label = None;
527 XSetWindowBackground(display, frame.window_label,
528 texture->getColor()->getPixel());
529 } else {
530 frame.label =
531 image_ctrl->renderImage(frame.window_label_w, frame.label_h, texture);
532 XSetWindowBackgroundPixmap(display, frame.window_label, frame.label);
533 }
534 if (tmp) image_ctrl->removeImage(tmp);
535
536 tmp = frame.wlabel;
537 texture = &(screen.getToolbarStyle()->label);
538 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
539 frame.wlabel = None;
540 XSetWindowBackground(display, frame.workspace_label,
541 texture->getColor()->getPixel());
542 } else {
543 frame.wlabel =
544 image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
545 XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
546 }
547 if (tmp) image_ctrl->removeImage(tmp);
548
549 tmp = frame.clk;
550 texture = &(screen.getToolbarStyle()->clock);
551 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
552 frame.clk = None;
553 XSetWindowBackground(display, frame.clock,
554 texture->getColor()->getPixel());
555 } else {
556 frame.clk =
557 image_ctrl->renderImage(frame.clock_w, frame.label_h, texture);
558 XSetWindowBackgroundPixmap(display, frame.clock, frame.clk);
559 }
560 if (tmp) image_ctrl->removeImage(tmp);
561
562 tmp = frame.button;
563 texture = &(screen.getToolbarStyle()->button);
564 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
565 frame.button = None;
566
567 frame.button_pixel = texture->getColor()->getPixel();
568 XSetWindowBackground(display, frame.psbutton, frame.button_pixel);
569 XSetWindowBackground(display, frame.nsbutton, frame.button_pixel);
570 XSetWindowBackground(display, frame.pwbutton, frame.button_pixel);
571 XSetWindowBackground(display, frame.nwbutton, frame.button_pixel);
572 } else {
573 frame.button =
574 image_ctrl->renderImage(frame.button_w, frame.button_w, texture);
575
576 XSetWindowBackgroundPixmap(display, frame.psbutton, frame.button);
577 XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.button);
578 XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.button);
579 XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.button);
580 }
581 if (tmp) image_ctrl->removeImage(tmp);
582
583 tmp = frame.pbutton;
584 texture = &(screen.getToolbarStyle()->pressed);
585 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
586 frame.pbutton = None;
587 frame.pbutton_pixel = texture->getColor()->getPixel();
588 } else {
589 frame.pbutton =
590 image_ctrl->renderImage(frame.button_w, frame.button_w, texture);
591 }
592 if (tmp) image_ctrl->removeImage(tmp);
593
594 XSetWindowBorder(display, frame.window,
595 screen.getBorderColor()->getPixel());
596 XSetWindowBorderWidth(display, frame.window, screen.getBorderWidth());
597
598 XClearWindow(display, frame.window);
599 XClearWindow(display, frame.workspace_label);
600 XClearWindow(display, frame.window_label);
601 XClearWindow(display, frame.clock);
602 XClearWindow(display, frame.psbutton);
603 XClearWindow(display, frame.nsbutton);
604 XClearWindow(display, frame.pwbutton);
605 XClearWindow(display, frame.nwbutton);
606
607 redrawWindowLabel();
608 redrawWorkspaceLabel();
609 redrawPrevWorkspaceButton();
610 redrawNextWorkspaceButton();
611 redrawPrevWindowButton();
612 redrawNextWindowButton();
613 checkClock(True);
614
615 toolbarmenu->reconfigure();
616 }
617
618
619 #ifdef HAVE_STRFTIME
620 void Toolbar::checkClock(Bool redraw) {
621 #else // !HAVE_STRFTIME
622 void Toolbar::checkClock(Bool redraw, Bool date) {
623 #endif // HAVE_STRFTIME
624 time_t tmp = 0;
625 struct tm *tt = 0;
626
627 if ((tmp = time(NULL)) != -1) {
628 if (! (tt = localtime(&tmp))) return;
629 if (tt->tm_min != frame.minute || tt->tm_hour != frame.hour) {
630 frame.hour = tt->tm_hour;
631 frame.minute = tt->tm_min;
632 XClearWindow(display, frame.clock);
633 redraw = True;
634 }
635 }
636
637 if (redraw) {
638 #ifdef HAVE_STRFTIME
639 char t[1024];
640 if (! strftime(t, 1024, screen.strftimeFormat(), tt))
641 return;
642 #else // !HAVE_STRFTIME
643 char t[9];
644 if (date) {
645 // format the date... with special consideration for y2k ;)
646 if (screen.getDateFormat() == Openbox::B_EuropeanDate)
647 sprintf(t, 18n->getMessage(ToolbarSet, ToolbarNoStrftimeDateFormatEu,
648 "%02d.%02d.%02d"),
649 tt->tm_mday, tt->tm_mon + 1,
650 (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year);
651 else
652 sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeDateFormat,
653 "%02d/%02d/%02d"),
654 tt->tm_mon + 1, tt->tm_mday,
655 (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year);
656 } else {
657 if (screen.isClock24Hour())
658 sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeTimeFormat24,
659 " %02d:%02d "),
660 frame.hour, frame.minute);
661 else
662 sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeTimeFormat12,
663 "%02d:%02d %sm"),
664 ((frame.hour > 12) ? frame.hour - 12 :
665 ((frame.hour == 0) ? 12 : frame.hour)), frame.minute,
666 ((frame.hour >= 12) ?
667 i18n->getMessage(ToolbarSet,
668 ToolbarNoStrftimeTimeFormatP, "p") :
669 i18n->getMessage(ToolbarSet,
670 ToolbarNoStrftimeTimeFormatA, "a")));
671 }
672 #endif // HAVE_STRFTIME
673
674 int dx = (frame.bevel_w * 2), dlen = strlen(t);
675 unsigned int l;
676
677 if (i18n->multibyte()) {
678 XRectangle ink, logical;
679 XmbTextExtents(screen.getToolbarStyle()->fontset,
680 t, dlen, &ink, &logical);
681 l = logical.width;
682 } else {
683 l = XTextWidth(screen.getToolbarStyle()->font, t, dlen);
684 }
685
686 l += (frame.bevel_w * 4);
687
688 if (l > frame.clock_w) {
689 for (; dlen >= 0; dlen--) {
690 if (i18n->multibyte()) {
691 XRectangle ink, logical;
692 XmbTextExtents(screen.getToolbarStyle()->fontset,
693 t, dlen, &ink, &logical);
694 l = logical.width;
695 } else {
696 l = XTextWidth(screen.getToolbarStyle()->font, t, dlen);
697 }
698 l+= (frame.bevel_w * 4);
699
700 if (l < frame.clock_w)
701 break;
702 }
703 }
704 switch (screen.getToolbarStyle()->justify) {
705 case BScreen::RightJustify:
706 dx += frame.clock_w - l;
707 break;
708
709 case BScreen::CenterJustify:
710 dx += (frame.clock_w - l) / 2;
711 break;
712 }
713
714 ToolbarStyle *style = screen.getToolbarStyle();
715 if (i18n->multibyte())
716 XmbDrawString(display, frame.clock, style->fontset, style->c_text_gc,
717 dx, (1 - style->fontset_extents->max_ink_extent.y),
718 t, dlen);
719 else
720 XDrawString(display, frame.clock, style->c_text_gc, dx,
721 (style->font->ascent + 1), t, dlen);
722 }
723 }
724
725
726 void Toolbar::redrawWindowLabel(Bool redraw) {
727 OpenboxWindow *foc = screen.getOpenbox().focusedWindow();
728 if (foc == (OpenboxWindow *) 0) {
729 XClearWindow(display, frame.window_label);
730 } else {
731 if (redraw)
732 XClearWindow(display, frame.window_label);
733
734 if (foc->getScreen() != &screen) return;
735
736 int dx = (frame.bevel_w * 2), dlen = strlen(*foc->getTitle());
737 unsigned int l;
738
739 if (i18n->multibyte()) {
740 XRectangle ink, logical;
741 XmbTextExtents(screen.getToolbarStyle()->fontset, *foc->getTitle(),
742 dlen, &ink, &logical);
743 l = logical.width;
744 } else {
745 l = XTextWidth(screen.getToolbarStyle()->font, *foc->getTitle(), dlen);
746 }
747 l += (frame.bevel_w * 4);
748
749 if (l > frame.window_label_w) {
750 for (; dlen >= 0; dlen--) {
751 if (i18n->multibyte()) {
752 XRectangle ink, logical;
753 XmbTextExtents(screen.getToolbarStyle()->fontset,
754 *foc->getTitle(), dlen, &ink, &logical);
755 l = logical.width;
756 } else {
757 l = XTextWidth(screen.getToolbarStyle()->font,
758 *foc->getTitle(), dlen);
759 }
760 l += (frame.bevel_w * 4);
761
762 if (l < frame.window_label_w)
763 break;
764 }
765 }
766 switch (screen.getToolbarStyle()->justify) {
767 case BScreen::RightJustify:
768 dx += frame.window_label_w - l;
769 break;
770
771 case BScreen::CenterJustify:
772 dx += (frame.window_label_w - l) / 2;
773 break;
774 }
775
776 ToolbarStyle *style = screen.getToolbarStyle();
777 if (i18n->multibyte())
778 XmbDrawString(display, frame.window_label, style->fontset,
779 style->w_text_gc, dx,
780 (1 - style->fontset_extents->max_ink_extent.y),
781 *foc->getTitle(), dlen);
782 else
783 XDrawString(display, frame.window_label, style->w_text_gc, dx,
784 (style->font->ascent + 1), *foc->getTitle(), dlen);
785 }
786 }
787
788
789 void Toolbar::redrawWorkspaceLabel(Bool redraw) {
790 if (screen.getCurrentWorkspace()->getName()) {
791 if (redraw)
792 XClearWindow(display, frame.workspace_label);
793
794 int dx = (frame.bevel_w * 2), dlen =
795 strlen(screen.getCurrentWorkspace()->getName());
796 unsigned int l;
797
798 if (i18n->multibyte()) {
799 XRectangle ink, logical;
800 XmbTextExtents(screen.getToolbarStyle()->fontset,
801 screen.getCurrentWorkspace()->getName(), dlen,
802 &ink, &logical);
803 l = logical.width;
804 } else {
805 l = XTextWidth(screen.getToolbarStyle()->font,
806 screen.getCurrentWorkspace()->getName(), dlen);
807 }
808 l += (frame.bevel_w * 4);
809
810 if (l > frame.workspace_label_w) {
811 for (; dlen >= 0; dlen--) {
812 if (i18n->multibyte()) {
813 XRectangle ink, logical;
814 XmbTextExtents(screen.getToolbarStyle()->fontset,
815 screen.getCurrentWorkspace()->getName(), dlen,
816 &ink, &logical);
817 l = logical.width;
818 } else {
819 l = XTextWidth(screen.getWindowStyle()->font,
820 screen.getCurrentWorkspace()->getName(), dlen);
821 }
822 l += (frame.bevel_w * 4);
823
824 if (l < frame.workspace_label_w)
825 break;
826 }
827 }
828 switch (screen.getToolbarStyle()->justify) {
829 case BScreen::RightJustify:
830 dx += frame.workspace_label_w - l;
831 break;
832
833 case BScreen::CenterJustify:
834 dx += (frame.workspace_label_w - l) / 2;
835 break;
836 }
837
838 ToolbarStyle *style = screen.getToolbarStyle();
839 if (i18n->multibyte())
840 XmbDrawString(display, frame.workspace_label, style->fontset,
841 style->l_text_gc, dx,
842 (1 - style->fontset_extents->max_ink_extent.y),
843 (char *) screen.getCurrentWorkspace()->getName(), dlen);
844 else
845 XDrawString(display, frame.workspace_label, style->l_text_gc, dx,
846 (style->font->ascent + 1),
847 (char *) screen.getCurrentWorkspace()->getName(), dlen);
848 }
849 }
850
851
852 void Toolbar::redrawPrevWorkspaceButton(Bool pressed, Bool redraw) {
853 if (redraw) {
854 if (pressed) {
855 if (frame.pbutton)
856 XSetWindowBackgroundPixmap(display, frame.psbutton, frame.pbutton);
857 else
858 XSetWindowBackground(display, frame.psbutton, frame.pbutton_pixel);
859 } else {
860 if (frame.button)
861 XSetWindowBackgroundPixmap(display, frame.psbutton, frame.button);
862 else
863 XSetWindowBackground(display, frame.psbutton, frame.button_pixel);
864 }
865 XClearWindow(display, frame.psbutton);
866 }
867
868 int hh = frame.button_w / 2, hw = frame.button_w / 2;
869
870 XPoint pts[3];
871 pts[0].x = hw - 2; pts[0].y = hh;
872 pts[1].x = 4; pts[1].y = 2;
873 pts[2].x = 0; pts[2].y = -4;
874
875 XFillPolygon(display, frame.psbutton, screen.getToolbarStyle()->b_pic_gc,
876 pts, 3, Convex, CoordModePrevious);
877 }
878
879
880 void Toolbar::redrawNextWorkspaceButton(Bool pressed, Bool redraw) {
881 if (redraw) {
882 if (pressed) {
883 if (frame.pbutton)
884 XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.pbutton);
885 else
886 XSetWindowBackground(display, frame.nsbutton, frame.pbutton_pixel);
887 } else {
888 if (frame.button)
889 XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.button);
890 else
891 XSetWindowBackground(display, frame.nsbutton, frame.button_pixel);
892 }
893 XClearWindow(display, frame.nsbutton);
894 }
895
896 int hh = frame.button_w / 2, hw = frame.button_w / 2;
897
898 XPoint pts[3];
899 pts[0].x = hw - 2; pts[0].y = hh - 2;
900 pts[1].x = 4; pts[1].y = 2;
901 pts[2].x = -4; pts[2].y = 2;
902
903 XFillPolygon(display, frame.nsbutton, screen.getToolbarStyle()->b_pic_gc,
904 pts, 3, Convex, CoordModePrevious);
905 }
906
907
908 void Toolbar::redrawPrevWindowButton(Bool pressed, Bool redraw) {
909 if (redraw) {
910 if (pressed) {
911 if (frame.pbutton)
912 XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.pbutton);
913 else
914 XSetWindowBackground(display, frame.pwbutton, frame.pbutton_pixel);
915 } else {
916 if (frame.button)
917 XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.button);
918 else
919 XSetWindowBackground(display, frame.pwbutton, frame.button_pixel);
920 }
921 XClearWindow(display, frame.pwbutton);
922 }
923
924 int hh = frame.button_w / 2, hw = frame.button_w / 2;
925
926 XPoint pts[3];
927 pts[0].x = hw - 2; pts[0].y = hh;
928 pts[1].x = 4; pts[1].y = 2;
929 pts[2].x = 0; pts[2].y = -4;
930
931 XFillPolygon(display, frame.pwbutton, screen.getToolbarStyle()->b_pic_gc,
932 pts, 3, Convex, CoordModePrevious);
933 }
934
935
936 void Toolbar::redrawNextWindowButton(Bool pressed, Bool redraw) {
937 if (redraw) {
938 if (pressed) {
939 if (frame.pbutton)
940 XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.pbutton);
941 else
942 XSetWindowBackground(display, frame.nwbutton, frame.pbutton_pixel);
943 } else {
944 if (frame.button)
945 XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.button);
946 else
947 XSetWindowBackground(display, frame.nwbutton, frame.button_pixel);
948 }
949 XClearWindow(display, frame.nwbutton);
950 }
951
952 int hh = frame.button_w / 2, hw = frame.button_w / 2;
953
954 XPoint pts[3];
955 pts[0].x = hw - 2; pts[0].y = hh - 2;
956 pts[1].x = 4; pts[1].y = 2;
957 pts[2].x = -4; pts[2].y = 2;
958
959 XFillPolygon(display, frame.nwbutton, screen.getToolbarStyle()->b_pic_gc,
960 pts, 3, Convex, CoordModePrevious);
961 }
962
963
964 void Toolbar::edit() {
965 Window window;
966 int foo;
967
968 m_editing = True;
969 if (XGetInputFocus(display, &window, &foo) &&
970 window == frame.workspace_label)
971 return;
972
973 XSetInputFocus(display, frame.workspace_label,
974 RevertToPointerRoot, 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 openbox.focusWindow((OpenboxWindow *) 0);
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.104756 seconds and 4 git commands to generate.