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