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
) : screen(scrn
),
70 openbox(scrn
.getOpenbox()), 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 hide_timer
->setTimeout(openbox
.getAutoRaiseDelay());
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 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 frame
.bevel_w
= screen
.getBevelWidth();
325 frame
.width
= screen
.size().w() * m_width_percent
/ 100;
327 if (i18n
->multibyte())
329 screen
.getToolbarStyle()->fontset_extents
->max_ink_extent
.height
;
331 frame
.height
= screen
.getToolbarStyle()->font
->ascent
+
332 screen
.getToolbarStyle()->font
->descent
;
333 frame
.button_w
= frame
.height
;
335 frame
.label_h
= frame
.height
;
336 frame
.height
+= (frame
.bevel_w
* 2);
338 switch (m_placement
) {
343 frame
.y_hidden
= screen
.getBevelWidth() - screen
.getBorderWidth()
349 frame
.y
= screen
.size().h() - frame
.height
350 - (screen
.getBorderWidth() * 2);
352 frame
.y_hidden
= screen
.size().h() - screen
.getBevelWidth()
353 - screen
.getBorderWidth();
357 frame
.x
= (screen
.size().w() - frame
.width
) / 2;
359 frame
.x_hidden
= frame
.x
;
360 frame
.y_hidden
= screen
.getBevelWidth() - screen
.getBorderWidth()
366 frame
.x
= (screen
.size().w() - frame
.width
) / 2;
367 frame
.y
= screen
.size().h() - frame
.height
368 - (screen
.getBorderWidth() * 2);
369 frame
.x_hidden
= frame
.x
;
370 frame
.y_hidden
= screen
.size().h() - screen
.getBevelWidth()
371 - screen
.getBorderWidth();
375 frame
.x
= screen
.size().w() - frame
.width
376 - (screen
.getBorderWidth() * 2);
378 frame
.x_hidden
= frame
.x
;
379 frame
.y_hidden
= screen
.getBevelWidth() - screen
.getBorderWidth()
384 frame
.x
= screen
.size().w() - frame
.width
385 - (screen
.getBorderWidth() * 2);
386 frame
.y
= screen
.size().h() - frame
.height
387 - (screen
.getBorderWidth() * 2);
388 frame
.x_hidden
= frame
.x
;
389 frame
.y_hidden
= screen
.size().h() - screen
.getBevelWidth()
390 - screen
.getBorderWidth();
395 time_t ttmp
= time(NULL
);
399 tt
= localtime(&ttmp
);
401 char t
[1025], *time_string
= (char *) 0;
402 int len
= strftime(t
, 1024, screen
.strftimeFormat(), tt
);
403 t
[len
++] = 'A'; // add size to the string for padding
404 t
[len
++] = 'A'; // add size to the string for padding
407 if (i18n
->multibyte()) {
408 XRectangle ink
, logical
;
409 XmbTextExtents(screen
.getToolbarStyle()->fontset
, t
, len
, &ink
,
411 frame
.clock_w
= logical
.width
;
413 // ben's additional solution to pad some space beside the numbers
415 // screen.getToolbarStyle()->fontset_extents->max_logical_extent.width *
418 // brad's solution, which is currently buggy, too big
420 // screen.getToolbarStyle()->fontset_extents->max_logical_extent.width
423 frame
.clock_w
= XTextWidth(screen
.getToolbarStyle()->font
, t
, len
);
424 // ben's additional solution to pad some space beside the numbers
425 //frame.clock_w += screen.getToolbarStyle()->font->max_bounds.width * 4;
426 // brad's solution again, too big
427 //frame.clock_w = screen.getToolbarStyle()->font->max_bounds.width * len;
429 frame
.clock_w
+= (frame
.bevel_w
* 4);
431 delete [] time_string
;
438 #else // !HAVE_STRFTIME
440 XTextWidth(screen
.getToolbarStyle()->font
,
441 i18n
->getMessage(ToolbarSet
, ToolbarNoStrftimeLength
,
443 strlen(i18n
->getMessage(ToolbarSet
, ToolbarNoStrftimeLength
,
444 "00:00000"))) + (frame
.bevel_w
* 4);
445 #endif // HAVE_STRFTIME
449 frame
.workspace_label_w
= 0;
451 for (i
= 0; i
< screen
.getWorkspaceCount(); i
++) {
452 if (i18n
->multibyte()) {
453 XRectangle ink
, logical
;
454 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
455 screen
.getWorkspace(i
)->getName(),
456 strlen(screen
.getWorkspace(i
)->getName()),
460 w
= XTextWidth(screen
.getToolbarStyle()->font
,
461 screen
.getWorkspace(i
)->getName(),
462 strlen(screen
.getWorkspace(i
)->getName()));
464 w
+= (frame
.bevel_w
* 4);
466 if (w
> frame
.workspace_label_w
) frame
.workspace_label_w
= w
;
469 if (frame
.workspace_label_w
< frame
.clock_w
)
470 frame
.workspace_label_w
= frame
.clock_w
;
471 else if (frame
.workspace_label_w
> frame
.clock_w
)
472 frame
.clock_w
= frame
.workspace_label_w
;
474 frame
.window_label_w
=
475 (frame
.width
- (frame
.clock_w
+ (frame
.button_w
* 4) +
476 frame
.workspace_label_w
+ (frame
.bevel_w
* 8) + 6));
479 XMoveResizeWindow(display
, frame
.window
, frame
.x_hidden
, frame
.y_hidden
,
480 frame
.width
, frame
.height
);
482 XMoveResizeWindow(display
, frame
.window
, frame
.x
, frame
.y
,
483 frame
.width
, frame
.height
);
486 XMoveResizeWindow(display
, frame
.workspace_label
, frame
.bevel_w
,
487 frame
.bevel_w
, frame
.workspace_label_w
,
489 XMoveResizeWindow(display
, frame
.psbutton
, (frame
.bevel_w
* 2) +
490 frame
.workspace_label_w
+ 1, frame
.bevel_w
+ 1,
491 frame
.button_w
, frame
.button_w
);
492 XMoveResizeWindow(display
,frame
.nsbutton
, (frame
.bevel_w
* 3) +
493 frame
.workspace_label_w
+ frame
.button_w
+ 2,
494 frame
.bevel_w
+ 1, frame
.button_w
, frame
.button_w
);
495 XMoveResizeWindow(display
, frame
.window_label
, (frame
.bevel_w
* 4) +
496 (frame
.button_w
* 2) + frame
.workspace_label_w
+ 3,
497 frame
.bevel_w
, frame
.window_label_w
, frame
.label_h
);
498 XMoveResizeWindow(display
, frame
.pwbutton
, (frame
.bevel_w
* 5) +
499 (frame
.button_w
* 2) + frame
.workspace_label_w
+
500 frame
.window_label_w
+ 4, frame
.bevel_w
+ 1,
501 frame
.button_w
, frame
.button_w
);
502 XMoveResizeWindow(display
, frame
.nwbutton
, (frame
.bevel_w
* 6) +
503 (frame
.button_w
* 3) + frame
.workspace_label_w
+
504 frame
.window_label_w
+ 5, frame
.bevel_w
+ 1,
505 frame
.button_w
, frame
.button_w
);
506 XMoveResizeWindow(display
, frame
.clock
, frame
.width
- frame
.clock_w
-
507 frame
.bevel_w
, frame
.bevel_w
, frame
.clock_w
,
510 Pixmap tmp
= frame
.base
;
511 BTexture
*texture
= &(screen
.getToolbarStyle()->toolbar
);
512 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
514 XSetWindowBackground(display
, frame
.window
,
515 texture
->getColor()->getPixel());
518 image_ctrl
->renderImage(frame
.width
, frame
.height
, texture
);
519 XSetWindowBackgroundPixmap(display
, frame
.window
, frame
.base
);
521 if (tmp
) image_ctrl
->removeImage(tmp
);
524 texture
= &(screen
.getToolbarStyle()->window
);
525 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
527 XSetWindowBackground(display
, frame
.window_label
,
528 texture
->getColor()->getPixel());
531 image_ctrl
->renderImage(frame
.window_label_w
, frame
.label_h
, texture
);
532 XSetWindowBackgroundPixmap(display
, frame
.window_label
, frame
.label
);
534 if (tmp
) image_ctrl
->removeImage(tmp
);
537 texture
= &(screen
.getToolbarStyle()->label
);
538 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
540 XSetWindowBackground(display
, frame
.workspace_label
,
541 texture
->getColor()->getPixel());
544 image_ctrl
->renderImage(frame
.workspace_label_w
, frame
.label_h
, texture
);
545 XSetWindowBackgroundPixmap(display
, frame
.workspace_label
, frame
.wlabel
);
547 if (tmp
) image_ctrl
->removeImage(tmp
);
550 texture
= &(screen
.getToolbarStyle()->clock
);
551 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
553 XSetWindowBackground(display
, frame
.clock
,
554 texture
->getColor()->getPixel());
557 image_ctrl
->renderImage(frame
.clock_w
, frame
.label_h
, texture
);
558 XSetWindowBackgroundPixmap(display
, frame
.clock
, frame
.clk
);
560 if (tmp
) image_ctrl
->removeImage(tmp
);
563 texture
= &(screen
.getToolbarStyle()->button
);
564 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
567 frame
.button_pixel
= texture
->getColor()->getPixel();
568 XSetWindowBackground(display
, frame
.psbutton
, frame
.button_pixel
);
569 XSetWindowBackground(display
, frame
.nsbutton
, frame
.button_pixel
);
570 XSetWindowBackground(display
, frame
.pwbutton
, frame
.button_pixel
);
571 XSetWindowBackground(display
, frame
.nwbutton
, frame
.button_pixel
);
574 image_ctrl
->renderImage(frame
.button_w
, frame
.button_w
, texture
);
576 XSetWindowBackgroundPixmap(display
, frame
.psbutton
, frame
.button
);
577 XSetWindowBackgroundPixmap(display
, frame
.nsbutton
, frame
.button
);
578 XSetWindowBackgroundPixmap(display
, frame
.pwbutton
, frame
.button
);
579 XSetWindowBackgroundPixmap(display
, frame
.nwbutton
, frame
.button
);
581 if (tmp
) image_ctrl
->removeImage(tmp
);
584 texture
= &(screen
.getToolbarStyle()->pressed
);
585 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
586 frame
.pbutton
= None
;
587 frame
.pbutton_pixel
= texture
->getColor()->getPixel();
590 image_ctrl
->renderImage(frame
.button_w
, frame
.button_w
, texture
);
592 if (tmp
) image_ctrl
->removeImage(tmp
);
594 XSetWindowBorder(display
, frame
.window
,
595 screen
.getBorderColor()->getPixel());
596 XSetWindowBorderWidth(display
, frame
.window
, screen
.getBorderWidth());
598 XClearWindow(display
, frame
.window
);
599 XClearWindow(display
, frame
.workspace_label
);
600 XClearWindow(display
, frame
.window_label
);
601 XClearWindow(display
, frame
.clock
);
602 XClearWindow(display
, frame
.psbutton
);
603 XClearWindow(display
, frame
.nsbutton
);
604 XClearWindow(display
, frame
.pwbutton
);
605 XClearWindow(display
, frame
.nwbutton
);
608 redrawWorkspaceLabel();
609 redrawPrevWorkspaceButton();
610 redrawNextWorkspaceButton();
611 redrawPrevWindowButton();
612 redrawNextWindowButton();
615 toolbarmenu
->reconfigure();
620 void Toolbar::checkClock(Bool redraw
) {
621 #else // !HAVE_STRFTIME
622 void Toolbar::checkClock(Bool redraw
, Bool date
) {
623 #endif // HAVE_STRFTIME
627 if ((tmp
= time(NULL
)) != -1) {
628 if (! (tt
= localtime(&tmp
))) return;
629 if (tt
->tm_min
!= frame
.minute
|| tt
->tm_hour
!= frame
.hour
) {
630 frame
.hour
= tt
->tm_hour
;
631 frame
.minute
= tt
->tm_min
;
632 XClearWindow(display
, frame
.clock
);
640 if (! strftime(t
, 1024, screen
.strftimeFormat(), tt
))
642 #else // !HAVE_STRFTIME
645 // format the date... with special consideration for y2k ;)
646 if (screen
.getDateFormat() == Openbox::B_EuropeanDate
)
647 sprintf(t
, 18n
->getMessage(ToolbarSet
, ToolbarNoStrftimeDateFormatEu
,
649 tt
->tm_mday
, tt
->tm_mon
+ 1,
650 (tt
->tm_year
>= 100) ? tt
->tm_year
- 100 : tt
->tm_year
);
652 sprintf(t
, i18n
->getMessage(ToolbarSet
, ToolbarNoStrftimeDateFormat
,
654 tt
->tm_mon
+ 1, tt
->tm_mday
,
655 (tt
->tm_year
>= 100) ? tt
->tm_year
- 100 : tt
->tm_year
);
657 if (screen
.isClock24Hour())
658 sprintf(t
, i18n
->getMessage(ToolbarSet
, ToolbarNoStrftimeTimeFormat24
,
660 frame
.hour
, frame
.minute
);
662 sprintf(t
, i18n
->getMessage(ToolbarSet
, ToolbarNoStrftimeTimeFormat12
,
664 ((frame
.hour
> 12) ? frame
.hour
- 12 :
665 ((frame
.hour
== 0) ? 12 : frame
.hour
)), frame
.minute
,
666 ((frame
.hour
>= 12) ?
667 i18n
->getMessage(ToolbarSet
,
668 ToolbarNoStrftimeTimeFormatP
, "p") :
669 i18n
->getMessage(ToolbarSet
,
670 ToolbarNoStrftimeTimeFormatA
, "a")));
672 #endif // HAVE_STRFTIME
674 int dx
= (frame
.bevel_w
* 2), dlen
= strlen(t
);
677 if (i18n
->multibyte()) {
678 XRectangle ink
, logical
;
679 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
680 t
, dlen
, &ink
, &logical
);
683 l
= XTextWidth(screen
.getToolbarStyle()->font
, t
, dlen
);
686 l
+= (frame
.bevel_w
* 4);
688 if (l
> frame
.clock_w
) {
689 for (; dlen
>= 0; dlen
--) {
690 if (i18n
->multibyte()) {
691 XRectangle ink
, logical
;
692 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
693 t
, dlen
, &ink
, &logical
);
696 l
= XTextWidth(screen
.getToolbarStyle()->font
, t
, dlen
);
698 l
+= (frame
.bevel_w
* 4);
700 if (l
< frame
.clock_w
)
704 switch (screen
.getToolbarStyle()->justify
) {
705 case BScreen::RightJustify
:
706 dx
+= frame
.clock_w
- l
;
709 case BScreen::CenterJustify
:
710 dx
+= (frame
.clock_w
- l
) / 2;
714 ToolbarStyle
*style
= screen
.getToolbarStyle();
715 if (i18n
->multibyte())
716 XmbDrawString(display
, frame
.clock
, style
->fontset
, style
->c_text_gc
,
717 dx
, (1 - style
->fontset_extents
->max_ink_extent
.y
),
720 XDrawString(display
, frame
.clock
, style
->c_text_gc
, dx
,
721 (style
->font
->ascent
+ 1), t
, dlen
);
726 void Toolbar::redrawWindowLabel(Bool redraw
) {
727 if (screen
.getOpenbox().focusedWindow()) {
729 XClearWindow(display
, frame
.window_label
);
731 OpenboxWindow
*foc
= screen
.getOpenbox().focusedWindow();
732 if (foc
->getScreen() != &screen
) return;
734 int dx
= (frame
.bevel_w
* 2), dlen
= strlen(*foc
->getTitle());
737 if (i18n
->multibyte()) {
738 XRectangle ink
, logical
;
739 XmbTextExtents(screen
.getToolbarStyle()->fontset
, *foc
->getTitle(),
740 dlen
, &ink
, &logical
);
743 l
= XTextWidth(screen
.getToolbarStyle()->font
, *foc
->getTitle(), dlen
);
745 l
+= (frame
.bevel_w
* 4);
747 if (l
> frame
.window_label_w
) {
748 for (; dlen
>= 0; dlen
--) {
749 if (i18n
->multibyte()) {
750 XRectangle ink
, logical
;
751 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
752 *foc
->getTitle(), dlen
, &ink
, &logical
);
755 l
= XTextWidth(screen
.getToolbarStyle()->font
,
756 *foc
->getTitle(), dlen
);
758 l
+= (frame
.bevel_w
* 4);
760 if (l
< frame
.window_label_w
)
764 switch (screen
.getToolbarStyle()->justify
) {
765 case BScreen::RightJustify
:
766 dx
+= frame
.window_label_w
- l
;
769 case BScreen::CenterJustify
:
770 dx
+= (frame
.window_label_w
- l
) / 2;
774 ToolbarStyle
*style
= screen
.getToolbarStyle();
775 if (i18n
->multibyte())
776 XmbDrawString(display
, frame
.window_label
, style
->fontset
,
777 style
->w_text_gc
, dx
,
778 (1 - style
->fontset_extents
->max_ink_extent
.y
),
779 *foc
->getTitle(), dlen
);
781 XDrawString(display
, frame
.window_label
, style
->w_text_gc
, dx
,
782 (style
->font
->ascent
+ 1), *foc
->getTitle(), dlen
);
784 XClearWindow(display
, frame
.window_label
);
789 void Toolbar::redrawWorkspaceLabel(Bool redraw
) {
790 if (screen
.getCurrentWorkspace()->getName()) {
792 XClearWindow(display
, frame
.workspace_label
);
794 int dx
= (frame
.bevel_w
* 2), dlen
=
795 strlen(screen
.getCurrentWorkspace()->getName());
798 if (i18n
->multibyte()) {
799 XRectangle ink
, logical
;
800 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
801 screen
.getCurrentWorkspace()->getName(), dlen
,
805 l
= XTextWidth(screen
.getToolbarStyle()->font
,
806 screen
.getCurrentWorkspace()->getName(), dlen
);
808 l
+= (frame
.bevel_w
* 4);
810 if (l
> frame
.workspace_label_w
) {
811 for (; dlen
>= 0; dlen
--) {
812 if (i18n
->multibyte()) {
813 XRectangle ink
, logical
;
814 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
815 screen
.getCurrentWorkspace()->getName(), dlen
,
819 l
= XTextWidth(screen
.getWindowStyle()->font
,
820 screen
.getCurrentWorkspace()->getName(), dlen
);
822 l
+= (frame
.bevel_w
* 4);
824 if (l
< frame
.workspace_label_w
)
828 switch (screen
.getToolbarStyle()->justify
) {
829 case BScreen::RightJustify
:
830 dx
+= frame
.workspace_label_w
- l
;
833 case BScreen::CenterJustify
:
834 dx
+= (frame
.workspace_label_w
- l
) / 2;
838 ToolbarStyle
*style
= screen
.getToolbarStyle();
839 if (i18n
->multibyte())
840 XmbDrawString(display
, frame
.workspace_label
, style
->fontset
,
841 style
->l_text_gc
, dx
,
842 (1 - style
->fontset_extents
->max_ink_extent
.y
),
843 (char *) screen
.getCurrentWorkspace()->getName(), dlen
);
845 XDrawString(display
, frame
.workspace_label
, style
->l_text_gc
, dx
,
846 (style
->font
->ascent
+ 1),
847 (char *) screen
.getCurrentWorkspace()->getName(), dlen
);
852 void Toolbar::redrawPrevWorkspaceButton(Bool pressed
, Bool redraw
) {
856 XSetWindowBackgroundPixmap(display
, frame
.psbutton
, frame
.pbutton
);
858 XSetWindowBackground(display
, frame
.psbutton
, frame
.pbutton_pixel
);
861 XSetWindowBackgroundPixmap(display
, frame
.psbutton
, frame
.button
);
863 XSetWindowBackground(display
, frame
.psbutton
, frame
.button_pixel
);
865 XClearWindow(display
, frame
.psbutton
);
868 int hh
= frame
.button_w
/ 2, hw
= frame
.button_w
/ 2;
871 pts
[0].x
= hw
- 2; pts
[0].y
= hh
;
872 pts
[1].x
= 4; pts
[1].y
= 2;
873 pts
[2].x
= 0; pts
[2].y
= -4;
875 XFillPolygon(display
, frame
.psbutton
, screen
.getToolbarStyle()->b_pic_gc
,
876 pts
, 3, Convex
, CoordModePrevious
);
880 void Toolbar::redrawNextWorkspaceButton(Bool pressed
, Bool redraw
) {
884 XSetWindowBackgroundPixmap(display
, frame
.nsbutton
, frame
.pbutton
);
886 XSetWindowBackground(display
, frame
.nsbutton
, frame
.pbutton_pixel
);
889 XSetWindowBackgroundPixmap(display
, frame
.nsbutton
, frame
.button
);
891 XSetWindowBackground(display
, frame
.nsbutton
, frame
.button_pixel
);
893 XClearWindow(display
, frame
.nsbutton
);
896 int hh
= frame
.button_w
/ 2, hw
= frame
.button_w
/ 2;
899 pts
[0].x
= hw
- 2; pts
[0].y
= hh
- 2;
900 pts
[1].x
= 4; pts
[1].y
= 2;
901 pts
[2].x
= -4; pts
[2].y
= 2;
903 XFillPolygon(display
, frame
.nsbutton
, screen
.getToolbarStyle()->b_pic_gc
,
904 pts
, 3, Convex
, CoordModePrevious
);
908 void Toolbar::redrawPrevWindowButton(Bool pressed
, Bool redraw
) {
912 XSetWindowBackgroundPixmap(display
, frame
.pwbutton
, frame
.pbutton
);
914 XSetWindowBackground(display
, frame
.pwbutton
, frame
.pbutton_pixel
);
917 XSetWindowBackgroundPixmap(display
, frame
.pwbutton
, frame
.button
);
919 XSetWindowBackground(display
, frame
.pwbutton
, frame
.button_pixel
);
921 XClearWindow(display
, frame
.pwbutton
);
924 int hh
= frame
.button_w
/ 2, hw
= frame
.button_w
/ 2;
927 pts
[0].x
= hw
- 2; pts
[0].y
= hh
;
928 pts
[1].x
= 4; pts
[1].y
= 2;
929 pts
[2].x
= 0; pts
[2].y
= -4;
931 XFillPolygon(display
, frame
.pwbutton
, screen
.getToolbarStyle()->b_pic_gc
,
932 pts
, 3, Convex
, CoordModePrevious
);
936 void Toolbar::redrawNextWindowButton(Bool pressed
, Bool redraw
) {
940 XSetWindowBackgroundPixmap(display
, frame
.nwbutton
, frame
.pbutton
);
942 XSetWindowBackground(display
, frame
.nwbutton
, frame
.pbutton_pixel
);
945 XSetWindowBackgroundPixmap(display
, frame
.nwbutton
, frame
.button
);
947 XSetWindowBackground(display
, frame
.nwbutton
, frame
.button_pixel
);
949 XClearWindow(display
, frame
.nwbutton
);
952 int hh
= frame
.button_w
/ 2, hw
= frame
.button_w
/ 2;
955 pts
[0].x
= hw
- 2; pts
[0].y
= hh
- 2;
956 pts
[1].x
= 4; pts
[1].y
= 2;
957 pts
[2].x
= -4; pts
[2].y
= 2;
959 XFillPolygon(display
, frame
.nwbutton
, screen
.getToolbarStyle()->b_pic_gc
,
960 pts
, 3, Convex
, CoordModePrevious
);
964 void Toolbar::edit() {
969 if (XGetInputFocus(display
, &window
, &foo
) &&
970 window
== frame
.workspace_label
)
973 XSetInputFocus(display
, frame
.workspace_label
,
974 RevertToPointerRoot
, CurrentTime
);
975 XClearWindow(display
, frame
.workspace_label
);
977 openbox
.setNoFocus(True
);
978 if (openbox
.focusedWindow())
979 openbox
.focusedWindow()->setFocusFlag(False
);
981 XDrawRectangle(display
, frame
.workspace_label
,
982 screen
.getWindowStyle()->l_text_focus_gc
,
983 frame
.workspace_label_w
/ 2, 0, 1,
986 // change the background of the window to that of an active window label
987 Pixmap tmp
= frame
.wlabel
;
988 BTexture
*texture
= &(screen
.getWindowStyle()->l_focus
);
989 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
991 XSetWindowBackground(display
, frame
.workspace_label
,
992 texture
->getColor()->getPixel());
995 image_ctrl
->renderImage(frame
.workspace_label_w
, frame
.label_h
, texture
);
996 XSetWindowBackgroundPixmap(display
, frame
.workspace_label
, frame
.wlabel
);
998 if (tmp
) image_ctrl
->removeImage(tmp
);
1002 void Toolbar::buttonPressEvent(XButtonEvent
*be
) {
1003 if (be
->button
== 1) {
1004 if (be
->window
== frame
.psbutton
)
1005 redrawPrevWorkspaceButton(True
, True
);
1006 else if (be
->window
== frame
.nsbutton
)
1007 redrawNextWorkspaceButton(True
, True
);
1008 else if (be
->window
== frame
.pwbutton
)
1009 redrawPrevWindowButton(True
, True
);
1010 else if (be
->window
== frame
.nwbutton
)
1011 redrawNextWindowButton(True
, True
);
1012 #ifndef HAVE_STRFTIME
1013 else if (be
->window
== frame
.clock
) {
1014 XClearWindow(display
, frame
.clock
);
1015 checkClock(True
, True
);
1017 #endif // HAVE_STRFTIME
1018 else if (! m_ontop
) {
1019 Window w
[1] = { frame
.window
};
1020 screen
.raiseWindows(w
, 1);
1022 } else if (be
->button
== 2 && (! m_ontop
)) {
1023 XLowerWindow(display
, frame
.window
);
1024 } else if (be
->button
== 3) {
1025 if (! toolbarmenu
->isVisible()) {
1028 x
= be
->x_root
- (toolbarmenu
->getWidth() / 2);
1029 y
= be
->y_root
- (toolbarmenu
->getHeight() / 2);
1033 else if (x
+ toolbarmenu
->getWidth() > screen
.size().w())
1034 x
= screen
.size().w() - toolbarmenu
->getWidth();
1038 else if (y
+ toolbarmenu
->getHeight() > screen
.size().h())
1039 y
= screen
.size().h() - toolbarmenu
->getHeight();
1041 toolbarmenu
->move(x
, y
);
1042 toolbarmenu
->show();
1044 toolbarmenu
->hide();
1050 void Toolbar::buttonReleaseEvent(XButtonEvent
*re
) {
1051 if (re
->button
== 1) {
1052 if (re
->window
== frame
.psbutton
) {
1053 redrawPrevWorkspaceButton(False
, True
);
1055 if (re
->x
>= 0 && re
->x
< (signed) frame
.button_w
&&
1056 re
->y
>= 0 && re
->y
< (signed) frame
.button_w
)
1057 if (screen
.getCurrentWorkspace()->getWorkspaceID() > 0)
1058 screen
.changeWorkspaceID(screen
.getCurrentWorkspace()->
1059 getWorkspaceID() - 1);
1061 screen
.changeWorkspaceID(screen
.getWorkspaceCount() - 1);
1062 } else if (re
->window
== frame
.nsbutton
) {
1063 redrawNextWorkspaceButton(False
, True
);
1065 if (re
->x
>= 0 && re
->x
< (signed) frame
.button_w
&&
1066 re
->y
>= 0 && re
->y
< (signed) frame
.button_w
)
1067 if (screen
.getCurrentWorkspace()->getWorkspaceID() <
1068 screen
.getWorkspaceCount() - 1)
1069 screen
.changeWorkspaceID(screen
.getCurrentWorkspace()->
1070 getWorkspaceID() + 1);
1072 screen
.changeWorkspaceID(0);
1073 } else if (re
->window
== frame
.pwbutton
) {
1074 redrawPrevWindowButton(False
, True
);
1076 if (re
->x
>= 0 && re
->x
< (signed) frame
.button_w
&&
1077 re
->y
>= 0 && re
->y
< (signed) frame
.button_w
)
1079 } else if (re
->window
== frame
.nwbutton
) {
1080 redrawNextWindowButton(False
, True
);
1082 if (re
->x
>= 0 && re
->x
< (signed) frame
.button_w
&&
1083 re
->y
>= 0 && re
->y
< (signed) frame
.button_w
)
1085 } else if (re
->window
== frame
.window_label
)
1086 screen
.raiseFocus();
1087 #ifndef HAVE_STRFTIME
1088 else if (re
->window
== frame
.clock
) {
1089 XClearWindow(display
, frame
.clock
);
1092 #endif // HAVE_STRFTIME
1097 void Toolbar::enterNotifyEvent(XCrossingEvent
*) {
1102 if (! hide_timer
->isTiming()) hide_timer
->start();
1104 if (hide_timer
->isTiming()) hide_timer
->stop();
1108 void Toolbar::leaveNotifyEvent(XCrossingEvent
*) {
1113 if (hide_timer
->isTiming()) hide_timer
->stop();
1114 } else if (! toolbarmenu
->isVisible()) {
1115 if (! hide_timer
->isTiming()) hide_timer
->start();
1120 void Toolbar::exposeEvent(XExposeEvent
*ee
) {
1121 if (ee
->window
== frame
.clock
) checkClock(True
);
1122 else if (ee
->window
== frame
.workspace_label
&& (! m_editing
))
1123 redrawWorkspaceLabel();
1124 else if (ee
->window
== frame
.window_label
) redrawWindowLabel();
1125 else if (ee
->window
== frame
.psbutton
) redrawPrevWorkspaceButton();
1126 else if (ee
->window
== frame
.nsbutton
) redrawNextWorkspaceButton();
1127 else if (ee
->window
== frame
.pwbutton
) redrawPrevWindowButton();
1128 else if (ee
->window
== frame
.nwbutton
) redrawNextWindowButton();
1132 void Toolbar::keyPressEvent(XKeyEvent
*ke
) {
1133 if (ke
->window
== frame
.workspace_label
&& m_editing
) {
1136 if (! new_workspace_name
) {
1137 new_workspace_name
= new char[128];
1140 if (! new_workspace_name
) return;
1145 XLookupString(ke
, keychar
, 1, &ks
, 0);
1147 // either we are told to end with a return or we hit the end of the buffer
1148 if (ks
== XK_Return
|| new_name_pos
== 127) {
1149 *(new_workspace_name
+ new_name_pos
) = 0;
1153 openbox
.setNoFocus(False
);
1154 if (openbox
.focusedWindow()) {
1155 openbox
.focusedWindow()->setInputFocus();
1156 openbox
.focusedWindow()->setFocusFlag(True
);
1158 XSetInputFocus(display
, PointerRoot
, None
, CurrentTime
);
1160 // check to make sure that new_name[0] != 0... otherwise we have a null
1161 // workspace name which causes serious problems, especially for the
1162 // Openbox::LoadRC() method.
1163 if (*new_workspace_name
) {
1164 screen
.getCurrentWorkspace()->setName(new_workspace_name
);
1165 screen
.getCurrentWorkspace()->getMenu()->hide();
1166 screen
.getWorkspacemenu()->
1167 remove(screen
.getCurrentWorkspace()->getWorkspaceID() + 2);
1168 screen
.getWorkspacemenu()->
1169 insert(screen
.getCurrentWorkspace()->getName(),
1170 screen
.getCurrentWorkspace()->getMenu(),
1171 screen
.getCurrentWorkspace()->getWorkspaceID() + 2);
1172 screen
.getWorkspacemenu()->update();
1175 delete [] new_workspace_name
;
1176 new_workspace_name
= (char *) 0;
1179 // reset the background to that of the workspace label (its normal
1181 Pixmap tmp
= frame
.wlabel
;
1182 BTexture
*texture
= &(screen
.getToolbarStyle()->label
);
1183 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
1184 frame
.wlabel
= None
;
1185 XSetWindowBackground(display
, frame
.workspace_label
,
1186 texture
->getColor()->getPixel());
1189 image_ctrl
->renderImage(frame
.workspace_label_w
, frame
.label_h
, texture
);
1190 XSetWindowBackgroundPixmap(display
, frame
.workspace_label
, frame
.wlabel
);
1192 if (tmp
) image_ctrl
->removeImage(tmp
);
1195 } else if (! (ks
== XK_Shift_L
|| ks
== XK_Shift_R
||
1196 ks
== XK_Control_L
|| ks
== XK_Control_R
||
1197 ks
== XK_Caps_Lock
|| ks
== XK_Shift_Lock
||
1198 ks
== XK_Meta_L
|| ks
== XK_Meta_R
||
1199 ks
== XK_Alt_L
|| ks
== XK_Alt_R
||
1200 ks
== XK_Super_L
|| ks
== XK_Super_R
||
1201 ks
== XK_Hyper_L
|| ks
== XK_Hyper_R
)) {
1202 if (ks
== XK_BackSpace
) {
1203 if (new_name_pos
> 0) {
1205 *(new_workspace_name
+ new_name_pos
) = '\0';
1207 *new_workspace_name
= '\0';
1210 *(new_workspace_name
+ new_name_pos
) = *keychar
;
1212 *(new_workspace_name
+ new_name_pos
) = '\0';
1215 XClearWindow(display
, frame
.workspace_label
);
1216 int l
= strlen(new_workspace_name
), tw
, x
;
1218 if (i18n
->multibyte()) {
1219 XRectangle ink
, logical
;
1220 XmbTextExtents(screen
.getToolbarStyle()->fontset
,
1221 new_workspace_name
, l
, &ink
, &logical
);
1224 tw
= XTextWidth(screen
.getToolbarStyle()->font
,
1225 new_workspace_name
, l
);
1227 x
= (frame
.workspace_label_w
- tw
) / 2;
1229 if (x
< (signed) frame
.bevel_w
) x
= frame
.bevel_w
;
1231 WindowStyle
*style
= screen
.getWindowStyle();
1232 if (i18n
->multibyte())
1233 XmbDrawString(display
, frame
.workspace_label
, style
->fontset
,
1234 style
->l_text_focus_gc
, x
,
1235 (1 - style
->fontset_extents
->max_ink_extent
.y
),
1236 new_workspace_name
, l
);
1238 XDrawString(display
, frame
.workspace_label
, style
->l_text_focus_gc
, x
,
1239 (style
->font
->ascent
+ 1),
1240 new_workspace_name
, l
);
1242 XDrawRectangle(display
, frame
.workspace_label
,
1243 screen
.getWindowStyle()->l_text_focus_gc
, x
+ tw
, 0, 1,
1252 void Toolbar::timeout() {
1256 gettimeofday(&now
, 0);
1257 clock_timer
->setTimeout((60 - (now
.tv_sec
% 60)) * 1000);
1261 void Toolbar::HideHandler::timeout() {
1262 toolbar
->m_hidden
= !toolbar
->m_hidden
;
1263 if (toolbar
->m_hidden
)
1264 XMoveWindow(toolbar
->display
, toolbar
->frame
.window
,
1265 toolbar
->frame
.x_hidden
, toolbar
->frame
.y_hidden
);
1267 XMoveWindow(toolbar
->display
, toolbar
->frame
.window
,
1268 toolbar
->frame
.x
, toolbar
->frame
.y
);
1272 Toolbarmenu::Toolbarmenu(Toolbar
&tb
) : Basemenu(tb
.screen
), toolbar(tb
) {
1273 setLabel(i18n
->getMessage(ToolbarSet
, ToolbarToolbarTitle
, "Toolbar"));
1276 placementmenu
= new Placementmenu(*this);
1278 insert(i18n
->getMessage(CommonSet
, CommonPlacementTitle
, "Placement"),
1280 insert(i18n
->getMessage(CommonSet
, CommonAlwaysOnTop
, "Always on top"), 1);
1281 insert(i18n
->getMessage(CommonSet
, CommonAutoHide
, "Auto hide"), 2);
1282 insert(i18n
->getMessage(ToolbarSet
, ToolbarEditWkspcName
,
1283 "Edit current workspace name"), 3);
1290 void Toolbarmenu::setValues() {
1291 setItemSelected(1, toolbar
.onTop());
1292 setItemSelected(2, toolbar
.autoHide());
1296 Toolbarmenu::~Toolbarmenu() {
1297 delete placementmenu
;
1301 void Toolbarmenu::itemSelected(int button
, int index
) {
1305 BasemenuItem
*item
= find(index
);
1308 switch (item
->function()) {
1309 case 1: { // always on top
1310 Bool change
= ((toolbar
.onTop()) ? False
: True
);
1311 toolbar
.setOnTop(change
);
1312 setItemSelected(1, change
);
1314 if (toolbar
.onTop()) toolbar
.screen
.raiseWindows((Window
*) 0, 0);
1318 case 2: { // auto hide
1319 Bool change
= ((toolbar
.autoHide()) ? False
: True
);
1320 toolbar
.setAutoHide(change
);
1321 setItemSelected(2, change
);
1324 toolbar
.screen
.getSlit()->reposition();
1329 case 3: { // edit current workspace name
1339 void Toolbarmenu::internal_hide() {
1340 Basemenu::internal_hide();
1341 if (toolbar
.autoHide() && ! toolbar
.isEditing())
1342 toolbar
.hide_handler
.timeout();
1346 void Toolbarmenu::reconfigure() {
1348 placementmenu
->reconfigure();
1350 Basemenu::reconfigure();
1354 Toolbarmenu::Placementmenu::Placementmenu(Toolbarmenu
&tm
)
1355 : Basemenu(tm
.toolbar
.screen
), toolbarmenu(tm
) {
1356 setLabel(i18n
->getMessage(ToolbarSet
, ToolbarToolbarPlacement
,
1357 "Toolbar Placement"));
1359 setMinimumSublevels(3);
1361 insert(i18n
->getMessage(CommonSet
, CommonPlacementTopLeft
,
1362 "Top Left"), Toolbar::TopLeft
);
1363 insert(i18n
->getMessage(CommonSet
, CommonPlacementBottomLeft
,
1364 "Bottom Left"), Toolbar::BottomLeft
);
1365 insert(i18n
->getMessage(CommonSet
, CommonPlacementTopCenter
,
1366 "Top Center"), Toolbar::TopCenter
);
1367 insert(i18n
->getMessage(CommonSet
, CommonPlacementBottomCenter
,
1368 "Bottom Center"), Toolbar::BottomCenter
);
1369 insert(i18n
->getMessage(CommonSet
, CommonPlacementTopRight
,
1370 "Top Right"), Toolbar::TopRight
);
1371 insert(i18n
->getMessage(CommonSet
, CommonPlacementBottomRight
,
1372 "Bottom Right"), Toolbar::BottomRight
);
1376 void Toolbarmenu::Placementmenu::itemSelected(int button
, int index
) {
1380 BasemenuItem
*item
= find(index
);
1383 toolbarmenu
.toolbar
.setPlacement(item
->function());
1385 toolbarmenu
.toolbar
.reconfigure();
1388 // reposition the slit as well to make sure it doesn't intersect the
1390 toolbarmenu
.toolbar
.screen
.getSlit()->reposition();