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