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)
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:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
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.
23 // stupid macros needed to access some functions in version 2 of the GNU C
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
35 #include "Clientmenu.h"
41 #include "Workspace.h"
42 #include "Workspacemenu.h"
44 #include <X11/keysym.h>
48 #endif // HAVE_STRING_H
52 #endif // HAVE_STDIO_H
54 #ifdef TIME_WITH_SYS_TIME
55 # include <sys/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
62 # endif // HAVE_SYS_TIME_H
63 #endif // TIME_WITH_SYS_TIME
69 Toolbar::Toolbar(BScreen
&scrn
, Resource
&conf
) : openbox(scrn
.getOpenbox()),
70 screen(scrn
), config(conf
)
74 // get the clock updating every minute
75 clock_timer
= new BTimer(openbox
, *this);
77 gettimeofday(&now
, 0);
78 clock_timer
->setTimeout((60 - (now
.tv_sec
% 60)) * 1000);
81 hide_handler
.toolbar
= this;
82 hide_timer
= new BTimer(openbox
, hide_handler
);
83 // the time out is set in ::reconfigure()
84 hide_timer
->fireOnce(True
);
86 image_ctrl
= screen
.getImageControl();
89 new_workspace_name
= (char *) 0;
91 frame
.grab_x
= frame
.grab_y
= 0;
93 toolbarmenu
= new Toolbarmenu(*this);
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
;
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);
113 attrib
.event_mask
= ButtonPressMask
| ButtonReleaseMask
| ExposureMask
|
114 KeyPressMask
| EnterWindowMask
;
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);
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);
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);
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);
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);
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);
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);
151 frame
.base
= frame
.label
= frame
.wlabel
= frame
.clk
= frame
.button
=
152 frame
.pbutton
= None
;
158 Rect
Toolbar::area() const {
159 int x
= ((m_hidden
) ? frame
.x_hidden
: frame
.x
);
161 if (screen
.hideToolbar()) y
= screen
.size().h();
162 else if (m_hidden
) y
= frame
.y_hidden
;
164 return Rect(x
, y
, frame
.width
, frame
.height
);
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
;
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
);
181 void Toolbar::unMapToolbar(){
182 //hidden so we can maximize over the toolbar
183 XUnmapWindow(display
, frame
.window
);
186 Toolbar::~Toolbar() {
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
);
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
);
204 XDestroyWindow(display
, frame
.workspace_label
);
205 XDestroyWindow(display
, frame
.window_label
);
206 XDestroyWindow(display
, frame
.clock
);
208 XDestroyWindow(display
, frame
.window
);
216 void Toolbar::setOnTop(bool b
) {
219 s
<< "session.screen" << screen
.getScreenNumber() << ".toolbar.onTop" << ends
;
220 config
.setValue(s
.str(), m_ontop
? "True" : "False");
221 s
.rdbuf()->freeze(0);
224 void Toolbar::setAutoHide(bool b
) {
227 s
<< "session.screen" << screen
.getScreenNumber() << ".toolbar.autoHide"
229 config
.setValue(s
.str(), m_autohide
? "True" : "False");
230 s
.rdbuf()->freeze(0);
233 void Toolbar::setWidthPercent(int w
) {
236 s
<< "session.screen" << screen
.getScreenNumber() << ".toolbar.widthPercent"
238 config
.setValue(s
.str(), m_width_percent
);
239 s
.rdbuf()->freeze(0);
242 void Toolbar::setPlacement(int p
) {
245 s
<< "session.screen" << screen
.getScreenNumber() << ".toolbar.placement"
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;
256 config
.setValue(s
.str(), placement
);
257 s
.rdbuf()->freeze(0);
260 void Toolbar::save() {
262 setAutoHide(m_autohide
);
263 setWidthPercent(m_width_percent
);
264 setPlacement(m_placement
);
267 void Toolbar::load() {
268 std::ostrstream rscreen
, rname
, rclass
;
272 rscreen
<< "session.screen" << screen
.getScreenNumber() << '.' << ends
;
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))
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
;
299 m_placement
= BottomCenter
;
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
))
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
;
317 m_hidden
= m_autohide
= false;
319 rscreen
.rdbuf()->freeze(0);
320 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
323 void Toolbar::reconfigure() {
324 hide_timer
->setTimeout(openbox
.getAutoRaiseDelay());
326 frame
.bevel_w
= screen
.getBevelWidth();
327 frame
.width
= screen
.size().w() * m_width_percent
/ 100;
329 if (i18n
.multibyte())
331 screen
.getToolbarStyle()->fontset_extents
->max_ink_extent
.height
;
333 frame
.height
= screen
.getToolbarStyle()->font
->ascent
+
334 screen
.getToolbarStyle()->font
->descent
;
335 frame
.button_w
= frame
.height
;
337 frame
.label_h
= frame
.height
;
338 frame
.height
+= (frame
.bevel_w
* 2);
340 switch (m_placement
) {
345 frame
.y_hidden
= screen
.getBevelWidth() - screen
.getBorderWidth()
351 frame
.y
= screen
.size().h() - frame
.height
352 - (screen
.getBorderWidth() * 2);
354 frame
.y_hidden
= screen
.size().h() - screen
.getBevelWidth()
355 - screen
.getBorderWidth();
359 frame
.x
= (screen
.size().w() - frame
.width
) / 2;
361 frame
.x_hidden
= frame
.x
;
362 frame
.y_hidden
= screen
.getBevelWidth() - screen
.getBorderWidth()
368 frame
.x
= (screen
.size().w() - frame
.width
) / 2;
369 frame
.y
= screen
.size().h() - frame
.height
370 - (screen
.getBorderWidth() * 2);
371 frame
.x_hidden
= frame
.x
;
372 frame
.y_hidden
= screen
.size().h() - screen
.getBevelWidth()
373 - screen
.getBorderWidth();
377 frame
.x
= screen
.size().w() - frame
.width
378 - (screen
.getBorderWidth() * 2);
380 frame
.x_hidden
= frame
.x
;
381 frame
.y_hidden
= screen
.getBevelWidth() - screen
.getBorderWidth()
386 frame
.x
= screen
.size().w() - frame
.width
387 - (screen
.getBorderWidth() * 2);
388 frame
.y
= screen
.size().h() - frame
.height
389 - (screen
.getBorderWidth() * 2);
390 frame
.x_hidden
= frame
.x
;
391 frame
.y_hidden
= screen
.size().h() - screen
.getBevelWidth()
392 - screen
.getBorderWidth();
397 time_t ttmp
= time(NULL
);
401 tt
= localtime(&ttmp
);
403 char t
[1025], *time_string
= (char *) 0;
404 int len
= strftime(t
, 1024, screen
.strftimeFormat(), tt
);
405 t
[len
++] = 'A'; // add size to the string for padding
406 t
[len
++] = 'A'; // add size to the string for padding
409 if (i18n
.multibyte()) {
410 XRectangle ink
, logical
;
411 XmbTextExtents(screen
.getToolbarStyle()->fontset
, t
, len
, &ink
,
413 frame
.clock_w
= logical
.width
;
415 // ben's additional solution to pad some space beside the numbers
417 // screen.getToolbarStyle()->fontset_extents->max_logical_extent.width *
420 // brad's solution, which is currently buggy, too big
422 // screen.getToolbarStyle()->fontset_extents->max_logical_extent.width
425 frame
.clock_w
= XTextWidth(screen
.getToolbarStyle()->font
, t
, len
);
426 // ben's additional solution to pad some space beside the numbers
427 //frame.clock_w += screen.getToolbarStyle()->font->max_bounds.width * 4;
428 // brad's solution again, too big
429 //frame.clock_w = screen.getToolbarStyle()->font->max_bounds.width * len;
431 frame
.clock_w
+= (frame
.bevel_w
* 4);
433 delete [] time_string
;
440 #else // !HAVE_STRFTIME
442 XTextWidth(screen
.getToolbarStyle()->font
,
443 i18n(ToolbarSet
, ToolbarNoStrftimeLength
,
445 strlen(i18n(ToolbarSet
, ToolbarNoStrftimeLength
,
446 "00:00000"))) + (frame
.bevel_w
* 4);
447 #endif // HAVE_STRFTIME
451 frame
.workspace_label_w
= 0;
453 for (i
= 0; i
< screen
.getWorkspaceCount(); i
++) {
454 if (i18n
.multibyte()) {
455 XRectangle ink
, logical
;
456 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
457 screen
.getWorkspace(i
)->getName(),
458 strlen(screen
.getWorkspace(i
)->getName()),
462 w
= XTextWidth(screen
.getToolbarStyle()->font
,
463 screen
.getWorkspace(i
)->getName(),
464 strlen(screen
.getWorkspace(i
)->getName()));
466 w
+= (frame
.bevel_w
* 4);
468 if (w
> frame
.workspace_label_w
) frame
.workspace_label_w
= w
;
471 if (frame
.workspace_label_w
< frame
.clock_w
)
472 frame
.workspace_label_w
= frame
.clock_w
;
473 else if (frame
.workspace_label_w
> frame
.clock_w
)
474 frame
.clock_w
= frame
.workspace_label_w
;
476 frame
.window_label_w
=
477 (frame
.width
- (frame
.clock_w
+ (frame
.button_w
* 4) +
478 frame
.workspace_label_w
+ (frame
.bevel_w
* 8) + 6));
481 XMoveResizeWindow(display
, frame
.window
, frame
.x_hidden
, frame
.y_hidden
,
482 frame
.width
, frame
.height
);
484 XMoveResizeWindow(display
, frame
.window
, frame
.x
, frame
.y
,
485 frame
.width
, frame
.height
);
488 XMoveResizeWindow(display
, frame
.workspace_label
, frame
.bevel_w
,
489 frame
.bevel_w
, frame
.workspace_label_w
,
491 XMoveResizeWindow(display
, frame
.psbutton
, (frame
.bevel_w
* 2) +
492 frame
.workspace_label_w
+ 1, frame
.bevel_w
+ 1,
493 frame
.button_w
, frame
.button_w
);
494 XMoveResizeWindow(display
,frame
.nsbutton
, (frame
.bevel_w
* 3) +
495 frame
.workspace_label_w
+ frame
.button_w
+ 2,
496 frame
.bevel_w
+ 1, frame
.button_w
, frame
.button_w
);
497 XMoveResizeWindow(display
, frame
.window_label
, (frame
.bevel_w
* 4) +
498 (frame
.button_w
* 2) + frame
.workspace_label_w
+ 3,
499 frame
.bevel_w
, frame
.window_label_w
, frame
.label_h
);
500 XMoveResizeWindow(display
, frame
.pwbutton
, (frame
.bevel_w
* 5) +
501 (frame
.button_w
* 2) + frame
.workspace_label_w
+
502 frame
.window_label_w
+ 4, frame
.bevel_w
+ 1,
503 frame
.button_w
, frame
.button_w
);
504 XMoveResizeWindow(display
, frame
.nwbutton
, (frame
.bevel_w
* 6) +
505 (frame
.button_w
* 3) + frame
.workspace_label_w
+
506 frame
.window_label_w
+ 5, frame
.bevel_w
+ 1,
507 frame
.button_w
, frame
.button_w
);
508 XMoveResizeWindow(display
, frame
.clock
, frame
.width
- frame
.clock_w
-
509 frame
.bevel_w
, frame
.bevel_w
, frame
.clock_w
,
512 Pixmap tmp
= frame
.base
;
513 BTexture
*texture
= &(screen
.getToolbarStyle()->toolbar
);
514 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
516 XSetWindowBackground(display
, frame
.window
,
517 texture
->getColor()->getPixel());
520 image_ctrl
->renderImage(frame
.width
, frame
.height
, texture
);
521 XSetWindowBackgroundPixmap(display
, frame
.window
, frame
.base
);
523 if (tmp
) image_ctrl
->removeImage(tmp
);
526 texture
= &(screen
.getToolbarStyle()->window
);
527 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
529 XSetWindowBackground(display
, frame
.window_label
,
530 texture
->getColor()->getPixel());
533 image_ctrl
->renderImage(frame
.window_label_w
, frame
.label_h
, texture
);
534 XSetWindowBackgroundPixmap(display
, frame
.window_label
, frame
.label
);
536 if (tmp
) image_ctrl
->removeImage(tmp
);
539 texture
= &(screen
.getToolbarStyle()->label
);
540 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
542 XSetWindowBackground(display
, frame
.workspace_label
,
543 texture
->getColor()->getPixel());
546 image_ctrl
->renderImage(frame
.workspace_label_w
, frame
.label_h
, texture
);
547 XSetWindowBackgroundPixmap(display
, frame
.workspace_label
, frame
.wlabel
);
549 if (tmp
) image_ctrl
->removeImage(tmp
);
552 texture
= &(screen
.getToolbarStyle()->clock
);
553 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
555 XSetWindowBackground(display
, frame
.clock
,
556 texture
->getColor()->getPixel());
559 image_ctrl
->renderImage(frame
.clock_w
, frame
.label_h
, texture
);
560 XSetWindowBackgroundPixmap(display
, frame
.clock
, frame
.clk
);
562 if (tmp
) image_ctrl
->removeImage(tmp
);
565 texture
= &(screen
.getToolbarStyle()->button
);
566 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
569 frame
.button_pixel
= texture
->getColor()->getPixel();
570 XSetWindowBackground(display
, frame
.psbutton
, frame
.button_pixel
);
571 XSetWindowBackground(display
, frame
.nsbutton
, frame
.button_pixel
);
572 XSetWindowBackground(display
, frame
.pwbutton
, frame
.button_pixel
);
573 XSetWindowBackground(display
, frame
.nwbutton
, frame
.button_pixel
);
576 image_ctrl
->renderImage(frame
.button_w
, frame
.button_w
, texture
);
578 XSetWindowBackgroundPixmap(display
, frame
.psbutton
, frame
.button
);
579 XSetWindowBackgroundPixmap(display
, frame
.nsbutton
, frame
.button
);
580 XSetWindowBackgroundPixmap(display
, frame
.pwbutton
, frame
.button
);
581 XSetWindowBackgroundPixmap(display
, frame
.nwbutton
, frame
.button
);
583 if (tmp
) image_ctrl
->removeImage(tmp
);
586 texture
= &(screen
.getToolbarStyle()->pressed
);
587 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
588 frame
.pbutton
= None
;
589 frame
.pbutton_pixel
= texture
->getColor()->getPixel();
592 image_ctrl
->renderImage(frame
.button_w
, frame
.button_w
, texture
);
594 if (tmp
) image_ctrl
->removeImage(tmp
);
596 XSetWindowBorder(display
, frame
.window
,
597 screen
.getBorderColor()->getPixel());
598 XSetWindowBorderWidth(display
, frame
.window
, screen
.getBorderWidth());
600 XClearWindow(display
, frame
.window
);
601 XClearWindow(display
, frame
.workspace_label
);
602 XClearWindow(display
, frame
.window_label
);
603 XClearWindow(display
, frame
.clock
);
604 XClearWindow(display
, frame
.psbutton
);
605 XClearWindow(display
, frame
.nsbutton
);
606 XClearWindow(display
, frame
.pwbutton
);
607 XClearWindow(display
, frame
.nwbutton
);
610 redrawWorkspaceLabel();
611 redrawPrevWorkspaceButton();
612 redrawNextWorkspaceButton();
613 redrawPrevWindowButton();
614 redrawNextWindowButton();
617 toolbarmenu
->reconfigure();
622 void Toolbar::checkClock(Bool redraw
) {
623 #else // !HAVE_STRFTIME
624 void Toolbar::checkClock(Bool redraw
, Bool date
) {
625 #endif // HAVE_STRFTIME
629 if ((tmp
= time(NULL
)) != -1) {
630 if (! (tt
= localtime(&tmp
))) return;
631 if (tt
->tm_min
!= frame
.minute
|| tt
->tm_hour
!= frame
.hour
) {
632 frame
.hour
= tt
->tm_hour
;
633 frame
.minute
= tt
->tm_min
;
634 XClearWindow(display
, frame
.clock
);
642 if (! strftime(t
, 1024, screen
.strftimeFormat(), tt
))
644 #else // !HAVE_STRFTIME
647 // format the date... with special consideration for y2k ;)
648 if (screen
.getDateFormat() == Openbox::B_EuropeanDate
)
649 sprintf(t
, 18n
->getMessage(ToolbarSet
, ToolbarNoStrftimeDateFormatEu
,
651 tt
->tm_mday
, tt
->tm_mon
+ 1,
652 (tt
->tm_year
>= 100) ? tt
->tm_year
- 100 : tt
->tm_year
);
654 sprintf(t
, i18n(ToolbarSet
, ToolbarNoStrftimeDateFormat
,
656 tt
->tm_mon
+ 1, tt
->tm_mday
,
657 (tt
->tm_year
>= 100) ? tt
->tm_year
- 100 : tt
->tm_year
);
659 if (screen
.isClock24Hour())
660 sprintf(t
, i18n(ToolbarSet
, ToolbarNoStrftimeTimeFormat24
,
662 frame
.hour
, frame
.minute
);
664 sprintf(t
, i18n(ToolbarSet
, ToolbarNoStrftimeTimeFormat12
,
666 ((frame
.hour
> 12) ? frame
.hour
- 12 :
667 ((frame
.hour
== 0) ? 12 : frame
.hour
)), frame
.minute
,
668 ((frame
.hour
>= 12) ?
670 ToolbarNoStrftimeTimeFormatP
, "p") :
672 ToolbarNoStrftimeTimeFormatA
, "a")));
674 #endif // HAVE_STRFTIME
676 int dx
= (frame
.bevel_w
* 2), dlen
= strlen(t
);
679 if (i18n
.multibyte()) {
680 XRectangle ink
, logical
;
681 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
682 t
, dlen
, &ink
, &logical
);
685 l
= XTextWidth(screen
.getToolbarStyle()->font
, t
, dlen
);
688 l
+= (frame
.bevel_w
* 4);
690 if (l
> frame
.clock_w
) {
691 for (; dlen
>= 0; dlen
--) {
692 if (i18n
.multibyte()) {
693 XRectangle ink
, logical
;
694 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
695 t
, dlen
, &ink
, &logical
);
698 l
= XTextWidth(screen
.getToolbarStyle()->font
, t
, dlen
);
700 l
+= (frame
.bevel_w
* 4);
702 if (l
< frame
.clock_w
)
706 switch (screen
.getToolbarStyle()->justify
) {
707 case BScreen::RightJustify
:
708 dx
+= frame
.clock_w
- l
;
711 case BScreen::CenterJustify
:
712 dx
+= (frame
.clock_w
- l
) / 2;
716 ToolbarStyle
*style
= screen
.getToolbarStyle();
717 if (i18n
.multibyte())
718 XmbDrawString(display
, frame
.clock
, style
->fontset
, style
->c_text_gc
,
719 dx
, (1 - style
->fontset_extents
->max_ink_extent
.y
),
722 XDrawString(display
, frame
.clock
, style
->c_text_gc
, dx
,
723 (style
->font
->ascent
+ 1), t
, dlen
);
728 void Toolbar::redrawWindowLabel(Bool redraw
) {
729 OpenboxWindow
*foc
= screen
.getOpenbox().focusedWindow();
730 if (foc
== (OpenboxWindow
*) 0) {
731 XClearWindow(display
, frame
.window_label
);
734 XClearWindow(display
, frame
.window_label
);
736 if (foc
->getScreen() != &screen
) return;
738 int dx
= (frame
.bevel_w
* 2), dlen
= strlen(*foc
->getTitle());
741 if (i18n
.multibyte()) {
742 XRectangle ink
, logical
;
743 XmbTextExtents(screen
.getToolbarStyle()->fontset
, *foc
->getTitle(),
744 dlen
, &ink
, &logical
);
747 l
= XTextWidth(screen
.getToolbarStyle()->font
, *foc
->getTitle(), dlen
);
749 l
+= (frame
.bevel_w
* 4);
751 if (l
> frame
.window_label_w
) {
752 for (; dlen
>= 0; dlen
--) {
753 if (i18n
.multibyte()) {
754 XRectangle ink
, logical
;
755 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
756 *foc
->getTitle(), dlen
, &ink
, &logical
);
759 l
= XTextWidth(screen
.getToolbarStyle()->font
,
760 *foc
->getTitle(), dlen
);
762 l
+= (frame
.bevel_w
* 4);
764 if (l
< frame
.window_label_w
)
768 switch (screen
.getToolbarStyle()->justify
) {
769 case BScreen::RightJustify
:
770 dx
+= frame
.window_label_w
- l
;
773 case BScreen::CenterJustify
:
774 dx
+= (frame
.window_label_w
- l
) / 2;
778 ToolbarStyle
*style
= screen
.getToolbarStyle();
779 if (i18n
.multibyte())
780 XmbDrawString(display
, frame
.window_label
, style
->fontset
,
781 style
->w_text_gc
, dx
,
782 (1 - style
->fontset_extents
->max_ink_extent
.y
),
783 *foc
->getTitle(), dlen
);
785 XDrawString(display
, frame
.window_label
, style
->w_text_gc
, dx
,
786 (style
->font
->ascent
+ 1), *foc
->getTitle(), dlen
);
791 void Toolbar::redrawWorkspaceLabel(Bool redraw
) {
792 if (screen
.getCurrentWorkspace()->getName()) {
794 XClearWindow(display
, frame
.workspace_label
);
796 int dx
= (frame
.bevel_w
* 2), dlen
=
797 strlen(screen
.getCurrentWorkspace()->getName());
800 if (i18n
.multibyte()) {
801 XRectangle ink
, logical
;
802 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
803 screen
.getCurrentWorkspace()->getName(), dlen
,
807 l
= XTextWidth(screen
.getToolbarStyle()->font
,
808 screen
.getCurrentWorkspace()->getName(), dlen
);
810 l
+= (frame
.bevel_w
* 4);
812 if (l
> frame
.workspace_label_w
) {
813 for (; dlen
>= 0; dlen
--) {
814 if (i18n
.multibyte()) {
815 XRectangle ink
, logical
;
816 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
817 screen
.getCurrentWorkspace()->getName(), dlen
,
821 l
= XTextWidth(screen
.getWindowStyle()->font
,
822 screen
.getCurrentWorkspace()->getName(), dlen
);
824 l
+= (frame
.bevel_w
* 4);
826 if (l
< frame
.workspace_label_w
)
830 switch (screen
.getToolbarStyle()->justify
) {
831 case BScreen::RightJustify
:
832 dx
+= frame
.workspace_label_w
- l
;
835 case BScreen::CenterJustify
:
836 dx
+= (frame
.workspace_label_w
- l
) / 2;
840 ToolbarStyle
*style
= screen
.getToolbarStyle();
841 if (i18n
.multibyte())
842 XmbDrawString(display
, frame
.workspace_label
, style
->fontset
,
843 style
->l_text_gc
, dx
,
844 (1 - style
->fontset_extents
->max_ink_extent
.y
),
845 (char *) screen
.getCurrentWorkspace()->getName(), dlen
);
847 XDrawString(display
, frame
.workspace_label
, style
->l_text_gc
, dx
,
848 (style
->font
->ascent
+ 1),
849 (char *) screen
.getCurrentWorkspace()->getName(), dlen
);
854 void Toolbar::redrawPrevWorkspaceButton(Bool pressed
, Bool redraw
) {
858 XSetWindowBackgroundPixmap(display
, frame
.psbutton
, frame
.pbutton
);
860 XSetWindowBackground(display
, frame
.psbutton
, frame
.pbutton_pixel
);
863 XSetWindowBackgroundPixmap(display
, frame
.psbutton
, frame
.button
);
865 XSetWindowBackground(display
, frame
.psbutton
, frame
.button_pixel
);
867 XClearWindow(display
, frame
.psbutton
);
870 int hh
= frame
.button_w
/ 2, hw
= frame
.button_w
/ 2;
873 pts
[0].x
= hw
- 2; pts
[0].y
= hh
;
874 pts
[1].x
= 4; pts
[1].y
= 2;
875 pts
[2].x
= 0; pts
[2].y
= -4;
877 XFillPolygon(display
, frame
.psbutton
, screen
.getToolbarStyle()->b_pic_gc
,
878 pts
, 3, Convex
, CoordModePrevious
);
882 void Toolbar::redrawNextWorkspaceButton(Bool pressed
, Bool redraw
) {
886 XSetWindowBackgroundPixmap(display
, frame
.nsbutton
, frame
.pbutton
);
888 XSetWindowBackground(display
, frame
.nsbutton
, frame
.pbutton_pixel
);
891 XSetWindowBackgroundPixmap(display
, frame
.nsbutton
, frame
.button
);
893 XSetWindowBackground(display
, frame
.nsbutton
, frame
.button_pixel
);
895 XClearWindow(display
, frame
.nsbutton
);
898 int hh
= frame
.button_w
/ 2, hw
= frame
.button_w
/ 2;
901 pts
[0].x
= hw
- 2; pts
[0].y
= hh
- 2;
902 pts
[1].x
= 4; pts
[1].y
= 2;
903 pts
[2].x
= -4; pts
[2].y
= 2;
905 XFillPolygon(display
, frame
.nsbutton
, screen
.getToolbarStyle()->b_pic_gc
,
906 pts
, 3, Convex
, CoordModePrevious
);
910 void Toolbar::redrawPrevWindowButton(Bool pressed
, Bool redraw
) {
914 XSetWindowBackgroundPixmap(display
, frame
.pwbutton
, frame
.pbutton
);
916 XSetWindowBackground(display
, frame
.pwbutton
, frame
.pbutton_pixel
);
919 XSetWindowBackgroundPixmap(display
, frame
.pwbutton
, frame
.button
);
921 XSetWindowBackground(display
, frame
.pwbutton
, frame
.button_pixel
);
923 XClearWindow(display
, frame
.pwbutton
);
926 int hh
= frame
.button_w
/ 2, hw
= frame
.button_w
/ 2;
929 pts
[0].x
= hw
- 2; pts
[0].y
= hh
;
930 pts
[1].x
= 4; pts
[1].y
= 2;
931 pts
[2].x
= 0; pts
[2].y
= -4;
933 XFillPolygon(display
, frame
.pwbutton
, screen
.getToolbarStyle()->b_pic_gc
,
934 pts
, 3, Convex
, CoordModePrevious
);
938 void Toolbar::redrawNextWindowButton(Bool pressed
, Bool redraw
) {
942 XSetWindowBackgroundPixmap(display
, frame
.nwbutton
, frame
.pbutton
);
944 XSetWindowBackground(display
, frame
.nwbutton
, frame
.pbutton_pixel
);
947 XSetWindowBackgroundPixmap(display
, frame
.nwbutton
, frame
.button
);
949 XSetWindowBackground(display
, frame
.nwbutton
, frame
.button_pixel
);
951 XClearWindow(display
, frame
.nwbutton
);
954 int hh
= frame
.button_w
/ 2, hw
= frame
.button_w
/ 2;
957 pts
[0].x
= hw
- 2; pts
[0].y
= hh
- 2;
958 pts
[1].x
= 4; pts
[1].y
= 2;
959 pts
[2].x
= -4; pts
[2].y
= 2;
961 XFillPolygon(display
, frame
.nwbutton
, screen
.getToolbarStyle()->b_pic_gc
,
962 pts
, 3, Convex
, CoordModePrevious
);
966 void Toolbar::edit() {
971 if (XGetInputFocus(display
, &window
, &foo
) &&
972 window
== frame
.workspace_label
)
975 XSetInputFocus(display
, frame
.workspace_label
,
976 RevertToPointerRoot
, CurrentTime
);
977 XClearWindow(display
, frame
.workspace_label
);
979 openbox
.setNoFocus(True
);
980 if (openbox
.focusedWindow())
981 openbox
.focusedWindow()->setFocusFlag(False
);
983 XDrawRectangle(display
, frame
.workspace_label
,
984 screen
.getWindowStyle()->l_text_focus_gc
,
985 frame
.workspace_label_w
/ 2, 0, 1,
988 // change the background of the window to that of an active window label
989 Pixmap tmp
= frame
.wlabel
;
990 BTexture
*texture
= &(screen
.getWindowStyle()->l_focus
);
991 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
993 XSetWindowBackground(display
, frame
.workspace_label
,
994 texture
->getColor()->getPixel());
997 image_ctrl
->renderImage(frame
.workspace_label_w
, frame
.label_h
, texture
);
998 XSetWindowBackgroundPixmap(display
, frame
.workspace_label
, frame
.wlabel
);
1000 if (tmp
) image_ctrl
->removeImage(tmp
);
1004 void Toolbar::buttonPressEvent(XButtonEvent
*be
) {
1005 if (be
->button
== 1) {
1006 if (be
->window
== frame
.psbutton
)
1007 redrawPrevWorkspaceButton(True
, True
);
1008 else if (be
->window
== frame
.nsbutton
)
1009 redrawNextWorkspaceButton(True
, True
);
1010 else if (be
->window
== frame
.pwbutton
)
1011 redrawPrevWindowButton(True
, True
);
1012 else if (be
->window
== frame
.nwbutton
)
1013 redrawNextWindowButton(True
, True
);
1014 #ifndef HAVE_STRFTIME
1015 else if (be
->window
== frame
.clock
) {
1016 XClearWindow(display
, frame
.clock
);
1017 checkClock(True
, True
);
1019 #endif // HAVE_STRFTIME
1020 else if (! m_ontop
) {
1021 Window w
[1] = { frame
.window
};
1022 screen
.raiseWindows(w
, 1);
1024 } else if (be
->button
== 2 && (! m_ontop
)) {
1025 XLowerWindow(display
, frame
.window
);
1026 } else if (be
->button
== 3) {
1027 if (! toolbarmenu
->isVisible()) {
1030 x
= be
->x_root
- (toolbarmenu
->getWidth() / 2);
1031 y
= be
->y_root
- (toolbarmenu
->getHeight() / 2);
1035 else if (x
+ toolbarmenu
->getWidth() > screen
.size().w())
1036 x
= screen
.size().w() - toolbarmenu
->getWidth();
1040 else if (y
+ toolbarmenu
->getHeight() > screen
.size().h())
1041 y
= screen
.size().h() - toolbarmenu
->getHeight();
1043 toolbarmenu
->move(x
, y
);
1044 toolbarmenu
->show();
1046 toolbarmenu
->hide();
1052 void Toolbar::buttonReleaseEvent(XButtonEvent
*re
) {
1053 if (re
->button
== 1) {
1054 if (re
->window
== frame
.psbutton
) {
1055 redrawPrevWorkspaceButton(False
, True
);
1057 if (re
->x
>= 0 && re
->x
< (signed) frame
.button_w
&&
1058 re
->y
>= 0 && re
->y
< (signed) frame
.button_w
)
1059 if (screen
.getCurrentWorkspace()->getWorkspaceID() > 0)
1060 screen
.changeWorkspaceID(screen
.getCurrentWorkspace()->
1061 getWorkspaceID() - 1);
1063 screen
.changeWorkspaceID(screen
.getWorkspaceCount() - 1);
1064 } else if (re
->window
== frame
.nsbutton
) {
1065 redrawNextWorkspaceButton(False
, True
);
1067 if (re
->x
>= 0 && re
->x
< (signed) frame
.button_w
&&
1068 re
->y
>= 0 && re
->y
< (signed) frame
.button_w
)
1069 if (screen
.getCurrentWorkspace()->getWorkspaceID() <
1070 screen
.getWorkspaceCount() - 1)
1071 screen
.changeWorkspaceID(screen
.getCurrentWorkspace()->
1072 getWorkspaceID() + 1);
1074 screen
.changeWorkspaceID(0);
1075 } else if (re
->window
== frame
.pwbutton
) {
1076 redrawPrevWindowButton(False
, True
);
1078 if (re
->x
>= 0 && re
->x
< (signed) frame
.button_w
&&
1079 re
->y
>= 0 && re
->y
< (signed) frame
.button_w
)
1081 } else if (re
->window
== frame
.nwbutton
) {
1082 redrawNextWindowButton(False
, True
);
1084 if (re
->x
>= 0 && re
->x
< (signed) frame
.button_w
&&
1085 re
->y
>= 0 && re
->y
< (signed) frame
.button_w
)
1087 } else if (re
->window
== frame
.window_label
)
1088 screen
.raiseFocus();
1089 #ifndef HAVE_STRFTIME
1090 else if (re
->window
== frame
.clock
) {
1091 XClearWindow(display
, frame
.clock
);
1094 #endif // HAVE_STRFTIME
1099 void Toolbar::enterNotifyEvent(XCrossingEvent
*) {
1104 if (! hide_timer
->isTiming()) hide_timer
->start();
1106 if (hide_timer
->isTiming()) hide_timer
->stop();
1110 void Toolbar::leaveNotifyEvent(XCrossingEvent
*) {
1115 if (hide_timer
->isTiming()) hide_timer
->stop();
1116 } else if (! toolbarmenu
->isVisible()) {
1117 if (! hide_timer
->isTiming()) hide_timer
->start();
1122 void Toolbar::exposeEvent(XExposeEvent
*ee
) {
1123 if (ee
->window
== frame
.clock
) checkClock(True
);
1124 else if (ee
->window
== frame
.workspace_label
&& (! m_editing
))
1125 redrawWorkspaceLabel();
1126 else if (ee
->window
== frame
.window_label
) redrawWindowLabel();
1127 else if (ee
->window
== frame
.psbutton
) redrawPrevWorkspaceButton();
1128 else if (ee
->window
== frame
.nsbutton
) redrawNextWorkspaceButton();
1129 else if (ee
->window
== frame
.pwbutton
) redrawPrevWindowButton();
1130 else if (ee
->window
== frame
.nwbutton
) redrawNextWindowButton();
1134 void Toolbar::keyPressEvent(XKeyEvent
*ke
) {
1135 if (ke
->window
== frame
.workspace_label
&& m_editing
) {
1138 if (! new_workspace_name
) {
1139 new_workspace_name
= new char[128];
1142 if (! new_workspace_name
) return;
1147 XLookupString(ke
, keychar
, 1, &ks
, 0);
1149 // either we are told to end with a return or we hit the end of the buffer
1150 if (ks
== XK_Return
|| new_name_pos
== 127) {
1151 *(new_workspace_name
+ new_name_pos
) = 0;
1155 openbox
.setNoFocus(False
);
1156 if (openbox
.focusedWindow()) {
1157 openbox
.focusedWindow()->setInputFocus();
1158 openbox
.focusedWindow()->setFocusFlag(True
);
1160 openbox
.focusWindow((OpenboxWindow
*) 0);
1162 // check to make sure that new_name[0] != 0... otherwise we have a null
1163 // workspace name which causes serious problems, especially for the
1164 // Openbox::LoadRC() method.
1165 if (*new_workspace_name
) {
1166 screen
.getCurrentWorkspace()->setName(new_workspace_name
);
1167 screen
.getCurrentWorkspace()->getMenu()->hide();
1168 screen
.getWorkspacemenu()->
1169 remove(screen
.getCurrentWorkspace()->getWorkspaceID() + 2);
1170 screen
.getWorkspacemenu()->
1171 insert(screen
.getCurrentWorkspace()->getName(),
1172 screen
.getCurrentWorkspace()->getMenu(),
1173 screen
.getCurrentWorkspace()->getWorkspaceID() + 2);
1174 screen
.getWorkspacemenu()->update();
1177 delete [] new_workspace_name
;
1178 new_workspace_name
= (char *) 0;
1181 // reset the background to that of the workspace label (its normal
1183 Pixmap tmp
= frame
.wlabel
;
1184 BTexture
*texture
= &(screen
.getToolbarStyle()->label
);
1185 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
1186 frame
.wlabel
= None
;
1187 XSetWindowBackground(display
, frame
.workspace_label
,
1188 texture
->getColor()->getPixel());
1191 image_ctrl
->renderImage(frame
.workspace_label_w
, frame
.label_h
, texture
);
1192 XSetWindowBackgroundPixmap(display
, frame
.workspace_label
, frame
.wlabel
);
1194 if (tmp
) image_ctrl
->removeImage(tmp
);
1197 } else if (! (ks
== XK_Shift_L
|| ks
== XK_Shift_R
||
1198 ks
== XK_Control_L
|| ks
== XK_Control_R
||
1199 ks
== XK_Caps_Lock
|| ks
== XK_Shift_Lock
||
1200 ks
== XK_Meta_L
|| ks
== XK_Meta_R
||
1201 ks
== XK_Alt_L
|| ks
== XK_Alt_R
||
1202 ks
== XK_Super_L
|| ks
== XK_Super_R
||
1203 ks
== XK_Hyper_L
|| ks
== XK_Hyper_R
)) {
1204 if (ks
== XK_BackSpace
) {
1205 if (new_name_pos
> 0) {
1207 *(new_workspace_name
+ new_name_pos
) = '\0';
1209 *new_workspace_name
= '\0';
1212 *(new_workspace_name
+ new_name_pos
) = *keychar
;
1214 *(new_workspace_name
+ new_name_pos
) = '\0';
1217 XClearWindow(display
, frame
.workspace_label
);
1218 int l
= strlen(new_workspace_name
), tw
, x
;
1220 if (i18n
.multibyte()) {
1221 XRectangle ink
, logical
;
1222 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
1223 new_workspace_name
, l
, &ink
, &logical
);
1226 tw
= XTextWidth(screen
.getToolbarStyle()->font
,
1227 new_workspace_name
, l
);
1229 x
= (frame
.workspace_label_w
- tw
) / 2;
1231 if (x
< (signed) frame
.bevel_w
) x
= frame
.bevel_w
;
1233 WindowStyle
*style
= screen
.getWindowStyle();
1234 if (i18n
.multibyte())
1235 XmbDrawString(display
, frame
.workspace_label
, style
->fontset
,
1236 style
->l_text_focus_gc
, x
,
1237 (1 - style
->fontset_extents
->max_ink_extent
.y
),
1238 new_workspace_name
, l
);
1240 XDrawString(display
, frame
.workspace_label
, style
->l_text_focus_gc
, x
,
1241 (style
->font
->ascent
+ 1),
1242 new_workspace_name
, l
);
1244 XDrawRectangle(display
, frame
.workspace_label
,
1245 screen
.getWindowStyle()->l_text_focus_gc
, x
+ tw
, 0, 1,
1254 void Toolbar::timeout() {
1258 gettimeofday(&now
, 0);
1259 clock_timer
->setTimeout((60 - (now
.tv_sec
% 60)) * 1000);
1263 void Toolbar::HideHandler::timeout() {
1264 toolbar
->m_hidden
= !toolbar
->m_hidden
;
1265 if (toolbar
->m_hidden
)
1266 XMoveWindow(toolbar
->display
, toolbar
->frame
.window
,
1267 toolbar
->frame
.x_hidden
, toolbar
->frame
.y_hidden
);
1269 XMoveWindow(toolbar
->display
, toolbar
->frame
.window
,
1270 toolbar
->frame
.x
, toolbar
->frame
.y
);
1274 Toolbarmenu::Toolbarmenu(Toolbar
&tb
) : Basemenu(tb
.screen
), toolbar(tb
) {
1275 setLabel(i18n(ToolbarSet
, ToolbarToolbarTitle
, "Toolbar"));
1278 placementmenu
= new Placementmenu(*this);
1280 insert(i18n(CommonSet
, CommonPlacementTitle
, "Placement"),
1282 insert(i18n(CommonSet
, CommonAlwaysOnTop
, "Always on top"), 1);
1283 insert(i18n(CommonSet
, CommonAutoHide
, "Auto hide"), 2);
1284 insert(i18n(ToolbarSet
, ToolbarEditWkspcName
,
1285 "Edit current workspace name"), 3);
1292 void Toolbarmenu::setValues() {
1293 setItemSelected(1, toolbar
.onTop());
1294 setItemSelected(2, toolbar
.autoHide());
1298 Toolbarmenu::~Toolbarmenu() {
1299 delete placementmenu
;
1303 void Toolbarmenu::itemSelected(int button
, int index
) {
1307 BasemenuItem
*item
= find(index
);
1310 switch (item
->function()) {
1311 case 1: { // always on top
1312 Bool change
= ((toolbar
.onTop()) ? False
: True
);
1313 toolbar
.setOnTop(change
);
1314 setItemSelected(1, change
);
1316 if (toolbar
.onTop()) toolbar
.screen
.raiseWindows((Window
*) 0, 0);
1320 case 2: { // auto hide
1321 Bool change
= ((toolbar
.autoHide()) ? False
: True
);
1322 toolbar
.setAutoHide(change
);
1323 setItemSelected(2, change
);
1326 toolbar
.screen
.getSlit()->reposition();
1331 case 3: { // edit current workspace name
1341 void Toolbarmenu::internal_hide() {
1342 Basemenu::internal_hide();
1343 if (toolbar
.autoHide() && ! toolbar
.isEditing())
1344 toolbar
.hide_handler
.timeout();
1348 void Toolbarmenu::reconfigure() {
1350 placementmenu
->reconfigure();
1352 Basemenu::reconfigure();
1356 Toolbarmenu::Placementmenu::Placementmenu(Toolbarmenu
&tm
)
1357 : Basemenu(tm
.toolbar
.screen
), toolbarmenu(tm
) {
1358 setLabel(i18n(ToolbarSet
, ToolbarToolbarPlacement
,
1359 "Toolbar Placement"));
1361 setMinimumSublevels(3);
1363 insert(i18n(CommonSet
, CommonPlacementTopLeft
,
1364 "Top Left"), Toolbar::TopLeft
);
1365 insert(i18n(CommonSet
, CommonPlacementBottomLeft
,
1366 "Bottom Left"), Toolbar::BottomLeft
);
1367 insert(i18n(CommonSet
, CommonPlacementTopCenter
,
1368 "Top Center"), Toolbar::TopCenter
);
1369 insert(i18n(CommonSet
, CommonPlacementBottomCenter
,
1370 "Bottom Center"), Toolbar::BottomCenter
);
1371 insert(i18n(CommonSet
, CommonPlacementTopRight
,
1372 "Top Right"), Toolbar::TopRight
);
1373 insert(i18n(CommonSet
, CommonPlacementBottomRight
,
1374 "Bottom Right"), Toolbar::BottomRight
);
1378 void Toolbarmenu::Placementmenu::itemSelected(int button
, int index
) {
1382 BasemenuItem
*item
= find(index
);
1385 toolbarmenu
.toolbar
.setPlacement(item
->function());
1387 toolbarmenu
.toolbar
.reconfigure();
1390 // reposition the slit as well to make sure it doesn't intersect the
1392 toolbarmenu
.toolbar
.screen
.getSlit()->reposition();