diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Window.cc | 265 |
1 files changed, 118 insertions, 147 deletions
diff --git a/src/Window.cc b/src/Window.cc index 9923a45..0f91a9e 100644 --- a/src/Window.cc +++ b/src/Window.cc | |||
@@ -253,6 +253,21 @@ struct TestCornerHelper { | |||
253 | } | 253 | } |
254 | }; | 254 | }; |
255 | 255 | ||
256 | // used in FluxboxWindow::updateAll() and FluxboxWindow::Setu | ||
257 | typedef FbTk::Resource<vector<WinButton::Type> > WBR; | ||
258 | |||
259 | // create a button ready to be used in the frame-titlebar | ||
260 | WinButton* makeButton(FluxboxWindow& win, FocusableTheme<WinButtonTheme>& btheme, WinButton::Type btype) { | ||
261 | |||
262 | FbTk::ThemeProxy<WinButtonTheme>& theme = win.screen().pressedWinButtonTheme(); | ||
263 | FbWinFrame& frame = win.frame(); | ||
264 | FbTk::FbWindow& parent = frame.titlebar(); | ||
265 | const unsigned int h = frame.buttonHeight(); | ||
266 | const unsigned int w = h; | ||
267 | |||
268 | return new WinButton(win, btheme, theme, btype, parent, 0, 0, w, h); | ||
269 | } | ||
270 | |||
256 | } | 271 | } |
257 | 272 | ||
258 | 273 | ||
@@ -3395,101 +3410,95 @@ void FluxboxWindow::kill() { | |||
3395 | } | 3410 | } |
3396 | 3411 | ||
3397 | void FluxboxWindow::setupWindow() { | 3412 | void FluxboxWindow::setupWindow() { |
3413 | |||
3398 | // sets up our window | 3414 | // sets up our window |
3399 | // we allow both to be done at once to share the commands | 3415 | // we allow both to be done at once to share the commands |
3400 | 3416 | FbTk::ResourceManager &rm = screen().resourceManager(); | |
3401 | using namespace FbTk; | 3417 | |
3402 | typedef FbTk::Resource<vector<WinButton::Type> > WinButtonsResource; | 3418 | struct { |
3403 | 3419 | std::string name; | |
3404 | string titlebar_name[2]; | 3420 | std::string alt_name; |
3405 | string titlebar_alt_name[2]; | 3421 | size_t n_buttons; |
3406 | titlebar_name[0] = screen().name() + ".titlebar.left"; | 3422 | WinButton::Type buttons[3]; |
3407 | titlebar_alt_name[0] = screen().altName() + ".Titlebar.Left"; | 3423 | } side[2] = { |
3408 | titlebar_name[1] = screen().name() + ".titlebar.right"; | 3424 | { |
3409 | titlebar_alt_name[1] = screen().altName() + ".Titlebar.Right"; | 3425 | screen().name() + ".titlebar.left", |
3410 | 3426 | screen().name() + ".Titlebar.Left", | |
3411 | WinButtonsResource *titlebar_side[2]; | 3427 | 1, { WinButton::STICK }, |
3412 | 3428 | }, | |
3429 | { | ||
3430 | screen().name() + ".titlebar.right", | ||
3431 | screen().name() + ".Titlebar.Right", | ||
3432 | 3, { WinButton::MINIMIZE, WinButton::MAXIMIZE, WinButton::CLOSE }, | ||
3433 | } | ||
3434 | }; | ||
3413 | 3435 | ||
3414 | 3436 | ||
3415 | ResourceManager &rm = screen().resourceManager(); | ||
3416 | |||
3417 | // create resource for titlebar | 3437 | // create resource for titlebar |
3418 | for (int i=0; i < 2; ++i) { | 3438 | for (size_t i = 0; i < sizeof(side)/sizeof(side[0]); ++i) { |
3419 | titlebar_side[i] = dynamic_cast<WinButtonsResource *>( | ||
3420 | rm.findResource( titlebar_name[i] ) ); | ||
3421 | 3439 | ||
3422 | if (titlebar_side[i] != 0) | 3440 | WBR* res = dynamic_cast<WBR*>(rm.findResource(side[i].name)); |
3441 | if (res != 0) | ||
3423 | continue; // find next resource too | 3442 | continue; // find next resource too |
3424 | 3443 | ||
3425 | WinButton::Type titlebar_left[] = { | 3444 | WinButton::Type* s = &side[i].buttons[0]; |
3426 | WinButton::STICK | 3445 | WinButton::Type* e = s + side[i].n_buttons; |
3427 | }; | 3446 | res = new WBR(rm, WBR::Type(s, e), side[i].name, side[i].alt_name); |
3428 | 3447 | screen().addManagedResource(res); | |
3429 | WinButton::Type titlebar_right[] = { | ||
3430 | WinButton::MINIMIZE, | ||
3431 | WinButton::MAXIMIZE, | ||
3432 | WinButton::CLOSE | ||
3433 | }; | ||
3434 | |||
3435 | WinButton::Type *begin = 0; | ||
3436 | WinButton::Type *end = 0; | ||
3437 | |||
3438 | if (i == 0) { | ||
3439 | begin = titlebar_left; | ||
3440 | end = titlebar_left + 1; | ||
3441 | } else { | ||
3442 | begin = titlebar_right; | ||
3443 | end = titlebar_right + 3; | ||
3444 | } | ||
3445 | |||
3446 | titlebar_side[i] = | ||
3447 | new WinButtonsResource(rm, | ||
3448 | WinButtonsResource::Type(begin, end), | ||
3449 | titlebar_name[i], titlebar_alt_name[i]); | ||
3450 | |||
3451 | |||
3452 | screen().addManagedResource(titlebar_side[i]); | ||
3453 | } | 3448 | } |
3454 | 3449 | ||
3455 | updateButtons(); | 3450 | updateButtons(); |
3456 | |||
3457 | // end setup frame | ||
3458 | |||
3459 | } | 3451 | } |
3460 | 3452 | ||
3453 | |||
3461 | void FluxboxWindow::updateButtons() { | 3454 | void FluxboxWindow::updateButtons() { |
3462 | string titlebar_name[2]; | ||
3463 | titlebar_name[0] = screen().name() + ".titlebar.left"; | ||
3464 | titlebar_name[1] = screen().name() + ".titlebar.right"; | ||
3465 | 3455 | ||
3466 | typedef FbTk::Resource<vector<WinButton::Type> > WinButtonsResource; | ||
3467 | WinButtonsResource *titlebar_side[2]; | ||
3468 | ResourceManager &rm = screen().resourceManager(); | 3456 | ResourceManager &rm = screen().resourceManager(); |
3469 | 3457 | size_t i; | |
3458 | size_t j; | ||
3459 | struct { | ||
3460 | std::string name; | ||
3461 | WBR* res; | ||
3462 | } sides[2] = { | ||
3463 | { screen().name() + ".titlebar.left", 0 }, | ||
3464 | { screen().name() + ".titlebar.right", 0 }, | ||
3465 | }; | ||
3466 | const size_t n_sides = sizeof(sides)/sizeof(sides[0]); | ||
3470 | bool need_update = false; | 3467 | bool need_update = false; |
3471 | // get resource for titlebar | 3468 | |
3472 | for (int i=0; i < 2; ++i) { | 3469 | |
3473 | titlebar_side[i] = dynamic_cast<WinButtonsResource *>( | 3470 | // get button resources for each titlebar and check if they differ |
3474 | rm.findResource( titlebar_name[i] ) ); | 3471 | for (i = 0; i < n_sides; ++i) { |
3472 | |||
3473 | sides[i].res = dynamic_cast<WBR*>(rm.findResource(sides[i].name)); | ||
3474 | |||
3475 | if (sides[i].res == 0) { | ||
3476 | if (!m_titlebar_buttons[i].empty()) { | ||
3477 | need_update = true; | ||
3478 | } | ||
3479 | continue; | ||
3480 | } | ||
3475 | 3481 | ||
3476 | // check if we need to update our buttons | 3482 | // check if we need to update our buttons |
3477 | size_t new_size = (*titlebar_side[i])->size(); | 3483 | const vector<WinButton::Type>& buttons = *(*sides[i].res); |
3478 | if (new_size != m_titlebar_buttons[i].size() || need_update) | 3484 | size_t s = buttons.size(); |
3485 | |||
3486 | if (s != m_titlebar_buttons[i].size()) { | ||
3479 | need_update = true; | 3487 | need_update = true; |
3480 | else { | 3488 | continue; |
3481 | for (size_t j=0; j < new_size && !need_update; j++) { | ||
3482 | if ((*(*titlebar_side[i]))[j] != m_titlebar_buttons[i][j]) | ||
3483 | need_update = true; | ||
3484 | } | ||
3485 | } | 3489 | } |
3486 | 3490 | ||
3491 | for (j = 0; !need_update && j < s; j++) { | ||
3492 | if (buttons[j] != m_titlebar_buttons[i][j]) { | ||
3493 | need_update = true; | ||
3494 | break; | ||
3495 | } | ||
3496 | } | ||
3487 | } | 3497 | } |
3488 | 3498 | ||
3489 | if (!need_update) | 3499 | if (!need_update) |
3490 | return; | 3500 | return; |
3491 | 3501 | ||
3492 | // clear old buttons from frame | ||
3493 | frame().removeAllButtons(); | 3502 | frame().removeAllButtons(); |
3494 | 3503 | ||
3495 | using namespace FbTk; | 3504 | using namespace FbTk; |
@@ -3505,129 +3514,91 @@ void FluxboxWindow::updateButtons() { | |||
3505 | CommandRef stick_cmd(new WindowCmd(*this, &FluxboxWindow::stick)); | 3514 | CommandRef stick_cmd(new WindowCmd(*this, &FluxboxWindow::stick)); |
3506 | CommandRef show_menu_cmd(new WindowCmd(*this, &FluxboxWindow::popupMenu)); | 3515 | CommandRef show_menu_cmd(new WindowCmd(*this, &FluxboxWindow::popupMenu)); |
3507 | 3516 | ||
3508 | for (size_t c = 0; c < 2 ; c++) { | 3517 | for (i = 0; i < n_sides; i++) { |
3509 | // get titlebar configuration for current side | 3518 | |
3510 | const vector<WinButton::Type> &dir = *(*titlebar_side[c]); | 3519 | if (sides[i].res == 0) { |
3511 | m_titlebar_buttons[c] = dir; | 3520 | continue; |
3521 | } | ||
3522 | |||
3523 | const vector<WinButton::Type>& buttons = *(*sides[i].res); | ||
3524 | m_titlebar_buttons[i] = buttons; | ||
3525 | |||
3526 | for (j = 0; j < buttons.size(); ++j) { | ||
3512 | 3527 | ||
3513 | for (size_t i=0; i < dir.size(); ++i) { | 3528 | WinButton* btn = 0; |
3514 | //create new buttons | ||
3515 | WinButton *winbtn = 0; | ||
3516 | 3529 | ||
3517 | switch (dir[i]) { | 3530 | switch (buttons[j]) { |
3518 | case WinButton::MINIMIZE: | 3531 | case WinButton::MINIMIZE: |
3519 | if (isIconifiable() && (m_state.deco_mask & WindowState::DECORM_ICONIFY)) { | 3532 | if (isIconifiable() && (m_state.deco_mask & WindowState::DECORM_ICONIFY)) { |
3520 | winbtn = new WinButton(*this, m_button_theme, | 3533 | btn = makeButton(*this, m_button_theme, buttons[j]); |
3521 | screen().pressedWinButtonTheme(), | 3534 | btn->setOnClick(iconify_cmd); |
3522 | WinButton::MINIMIZE, | ||
3523 | frame().titlebar(), | ||
3524 | 0, 0, 10, 10); | ||
3525 | winbtn->setOnClick(iconify_cmd); | ||
3526 | } | 3535 | } |
3527 | break; | 3536 | break; |
3528 | case WinButton::MAXIMIZE: | 3537 | case WinButton::MAXIMIZE: |
3529 | if (isMaximizable() && (m_state.deco_mask & WindowState::DECORM_MAXIMIZE) ) { | 3538 | if (isMaximizable() && (m_state.deco_mask & WindowState::DECORM_MAXIMIZE) ) { |
3530 | winbtn = new WinButton(*this, m_button_theme, | 3539 | btn = makeButton(*this, m_button_theme, buttons[j]); |
3531 | screen().pressedWinButtonTheme(), | 3540 | btn->setOnClick(maximize_cmd, 1); |
3532 | dir[i], | 3541 | btn->setOnClick(maximize_horiz_cmd, 3); |
3533 | frame().titlebar(), | 3542 | btn->setOnClick(maximize_vert_cmd, 2); |
3534 | 0, 0, 10, 10); | ||
3535 | winbtn->setOnClick(maximize_cmd, 1); | ||
3536 | winbtn->setOnClick(maximize_horiz_cmd, 3); | ||
3537 | winbtn->setOnClick(maximize_vert_cmd, 2); | ||
3538 | |||
3539 | } | 3543 | } |
3540 | break; | 3544 | break; |
3541 | case WinButton::CLOSE: | 3545 | case WinButton::CLOSE: |
3542 | if (m_client->isClosable() && (m_state.deco_mask & WindowState::DECORM_CLOSE)) { | 3546 | if (m_client->isClosable() && (m_state.deco_mask & WindowState::DECORM_CLOSE)) { |
3543 | winbtn = new WinButton(*this, m_button_theme, | 3547 | btn = makeButton(*this, m_button_theme, buttons[j]); |
3544 | screen().pressedWinButtonTheme(), | 3548 | btn->setOnClick(close_cmd); |
3545 | dir[i], | 3549 | btn->join(stateSig(), FbTk::MemFunIgnoreArgs(*btn, &WinButton::updateAll)); |
3546 | frame().titlebar(), | ||
3547 | 0, 0, 10, 10); | ||
3548 | |||
3549 | winbtn->setOnClick(close_cmd); | ||
3550 | winbtn->join(stateSig(), | ||
3551 | FbTk::MemFunIgnoreArgs(*winbtn, &WinButton::updateAll)); | ||
3552 | } | 3550 | } |
3553 | break; | 3551 | break; |
3554 | case WinButton::STICK: | 3552 | case WinButton::STICK: |
3555 | if (m_state.deco_mask & WindowState::DECORM_STICKY) { | 3553 | if (m_state.deco_mask & WindowState::DECORM_STICKY) { |
3556 | winbtn = new WinButton(*this, m_button_theme, | 3554 | btn = makeButton(*this, m_button_theme, buttons[j]); |
3557 | screen().pressedWinButtonTheme(), | 3555 | btn->join(stateSig(), FbTk::MemFunIgnoreArgs(*btn, &WinButton::updateAll)); |
3558 | dir[i], | 3556 | btn->setOnClick(stick_cmd); |
3559 | frame().titlebar(), | ||
3560 | 0, 0, 10, 10); | ||
3561 | |||
3562 | winbtn->join(stateSig(), | ||
3563 | FbTk::MemFunIgnoreArgs(*winbtn, &WinButton::updateAll)); | ||
3564 | winbtn->setOnClick(stick_cmd); | ||
3565 | } | 3557 | } |
3566 | break; | 3558 | break; |
3567 | case WinButton::SHADE: | 3559 | case WinButton::SHADE: |
3568 | if (m_state.deco_mask & WindowState::DECORM_SHADE) { | 3560 | if (m_state.deco_mask & WindowState::DECORM_SHADE) { |
3569 | winbtn = new WinButton(*this, m_button_theme, | 3561 | btn = makeButton(*this, m_button_theme, buttons[j]); |
3570 | screen().pressedWinButtonTheme(), | 3562 | btn->join(stateSig(), FbTk::MemFunIgnoreArgs(*btn, &WinButton::updateAll)); |
3571 | dir[i], | 3563 | btn->setOnClick(shade_cmd); |
3572 | frame().titlebar(), | ||
3573 | 0, 0, 10, 10); | ||
3574 | winbtn->join(stateSig(), | ||
3575 | FbTk::MemFunIgnoreArgs(*winbtn, &WinButton::updateAll)); | ||
3576 | winbtn->setOnClick(shade_cmd); | ||
3577 | } | 3564 | } |
3578 | break; | 3565 | break; |
3579 | case WinButton::MENUICON: | 3566 | case WinButton::MENUICON: |
3580 | if (m_state.deco_mask & WindowState::DECORM_MENU) { | 3567 | if (m_state.deco_mask & WindowState::DECORM_MENU) { |
3581 | winbtn = new WinButton(*this, m_button_theme, | 3568 | btn = makeButton(*this, m_button_theme, buttons[j]); |
3582 | screen().pressedWinButtonTheme(), | 3569 | btn->join(titleSig(), FbTk::MemFunIgnoreArgs(*btn, &WinButton::updateAll)); |
3583 | dir[i], | 3570 | btn->setOnClick(show_menu_cmd); |
3584 | frame().titlebar(), | ||
3585 | 0, 0, 10, 10); | ||
3586 | winbtn->join(titleSig(), | ||
3587 | FbTk::MemFunIgnoreArgs(*winbtn, &WinButton::updateAll)); | ||
3588 | winbtn->setOnClick(show_menu_cmd); | ||
3589 | } | 3571 | } |
3590 | break; | 3572 | break; |
3591 | 3573 | ||
3592 | case WinButton::LEFT_HALF: | 3574 | case WinButton::LEFT_HALF: |
3593 | { | 3575 | { |
3594 | winbtn = new WinButton(*this, m_button_theme, | 3576 | btn = makeButton(*this, m_button_theme, buttons[j]); |
3595 | screen().pressedWinButtonTheme(), | ||
3596 | dir[i], | ||
3597 | frame().titlebar(), | ||
3598 | 0, 0, 10, 10); | ||
3599 | |||
3600 | CommandRef lhalf_cmd(FbTk::CommandParser<void>::instance().parse("MacroCmd {MoveTo 0 0} {ResizeTo 50% 100%}")); | 3577 | CommandRef lhalf_cmd(FbTk::CommandParser<void>::instance().parse("MacroCmd {MoveTo 0 0} {ResizeTo 50% 100%}")); |
3601 | winbtn->setOnClick(lhalf_cmd); | 3578 | btn->setOnClick(lhalf_cmd); |
3602 | } | 3579 | } |
3603 | break; | 3580 | break; |
3604 | 3581 | ||
3605 | case WinButton::RIGHT_HALF: | 3582 | case WinButton::RIGHT_HALF: |
3606 | { | 3583 | { |
3607 | winbtn = new WinButton(*this, m_button_theme, | 3584 | btn = makeButton(*this, m_button_theme, buttons[j]); |
3608 | screen().pressedWinButtonTheme(), | ||
3609 | dir[i], | ||
3610 | frame().titlebar(), | ||
3611 | 0, 0, 10, 10); | ||
3612 | CommandRef rhalf_cmd(FbTk::CommandParser<void>::instance().parse("MacroCmd {MoveTo 50% 0} {ResizeTo 50% 100%}")); | 3585 | CommandRef rhalf_cmd(FbTk::CommandParser<void>::instance().parse("MacroCmd {MoveTo 50% 0} {ResizeTo 50% 100%}")); |
3613 | winbtn->setOnClick(rhalf_cmd); | 3586 | btn->setOnClick(rhalf_cmd); |
3614 | } | 3587 | } |
3615 | break; | 3588 | break; |
3616 | 3589 | ||
3617 | } | 3590 | } |
3618 | 3591 | ||
3619 | 3592 | ||
3620 | if (winbtn != 0) { | 3593 | if (btn != 0) { |
3621 | winbtn->show(); | 3594 | btn->show(); |
3622 | if (c == 0) | 3595 | if (i == 0) |
3623 | frame().addLeftButton(winbtn); | 3596 | frame().addLeftButton(btn); |
3624 | else | 3597 | else |
3625 | frame().addRightButton(winbtn); | 3598 | frame().addRightButton(btn); |
3626 | } | 3599 | } |
3627 | } //end for i | 3600 | } |
3628 | 3601 | } | |
3629 | |||
3630 | } // end for c | ||
3631 | 3602 | ||
3632 | frame().reconfigure(); | 3603 | frame().reconfigure(); |
3633 | } | 3604 | } |