aboutsummaryrefslogtreecommitdiff
path: root/src/CurrentWindowCmd.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/CurrentWindowCmd.cc')
-rw-r--r--src/CurrentWindowCmd.cc151
1 files changed, 116 insertions, 35 deletions
diff --git a/src/CurrentWindowCmd.cc b/src/CurrentWindowCmd.cc
index 8d27a3a..4363d0d 100644
--- a/src/CurrentWindowCmd.cc
+++ b/src/CurrentWindowCmd.cc
@@ -36,6 +36,7 @@
36#include "FbTk/stringstream.hh" 36#include "FbTk/stringstream.hh"
37#include "FbTk/StringUtil.hh" 37#include "FbTk/StringUtil.hh"
38#include "FbTk/Util.hh" 38#include "FbTk/Util.hh"
39#include "FbTk/RelCalcHelper.hh"
39 40
40#ifdef HAVE_CONFIG_H 41#ifdef HAVE_CONFIG_H
41#include "config.h" 42#include "config.h"
@@ -47,7 +48,6 @@
47#include <stdlib.h> 48#include <stdlib.h>
48#endif 49#endif
49 50
50
51using FbTk::Command; 51using FbTk::Command;
52 52
53namespace { 53namespace {
@@ -477,21 +477,59 @@ void MoveCmd::real_execute() {
477 fbwindow().move(fbwindow().x() + m_step_size_x, fbwindow().y() + m_step_size_y); 477 fbwindow().move(fbwindow().x() + m_step_size_x, fbwindow().y() + m_step_size_y);
478} 478}
479 479
480namespace {
481 template <typename Container>
482 static void parseToken(Container &container, int &d, bool &is_relative, bool &ignore) {
483 if (container.size() < 1)
484 return;
485
486 d = 0;
487 is_relative = false;
488 ignore = false;
489 if (container[0] == '*') {
490 ignore = true;
491 } else if (container[container.size() - 1] == '%') {
492 // its a percent
493 is_relative = true;
494 d = atoi(container.substr(0, container.size() - 1).c_str());
495 } else {
496 d = atoi(container.c_str());
497 }
498 }
499}
500
480FbTk::Command<void> *ResizeCmd::parse(const string &command, const string &args, 501FbTk::Command<void> *ResizeCmd::parse(const string &command, const string &args,
481 bool trusted) { 502 bool trusted) {
482 FbTk_istringstream is(args.c_str()); 503
483 int dx = 0, dy = 0; 504 typedef std::vector<string> StringTokens;
484 is >> dx >> dy; 505 StringTokens tokens;
485 if (command == "resizehorizontal") 506 FbTk::StringUtil::stringtok<StringTokens>(tokens, args);
507
508 if (tokens.size() < 1) {
509 return 0;
510 }
511
512 int dx, dy;
513 bool is_relative_x = false, is_relative_y = false, ignore_x = false, ignore_y = false;
514
515 if (command == "resizehorizontal") {
516 parseToken(tokens[0], dx, is_relative_x, ignore_x);
486 dy = 0; 517 dy = 0;
487 else if (command == "resizevertical") { 518 } else if (command == "resizevertical") {
488 dy = dx; 519 parseToken(tokens[0], dy, is_relative_y, ignore_y);
489 dx = 0; 520 dx = 0;
521 } else {
522 if (tokens.size() < 2) {
523 return 0;
524 }
525 parseToken(tokens[0], dx, is_relative_x, ignore_x);
526 parseToken(tokens[1], dy, is_relative_y, ignore_y);
490 } 527 }
491 528
492 if (command == "resizeto") 529 if (command == "resizeto") {
493 return new ResizeToCmd(dx, dy); 530 return new ResizeToCmd(dx, dy, is_relative_x, is_relative_y);
494 return new ResizeCmd(dx, dy); 531 }
532 return new ResizeCmd(dx, dy, is_relative_x, is_relative_y);
495} 533}
496 534
497REGISTER_COMMAND_PARSER(resize, ResizeCmd::parse, void); 535REGISTER_COMMAND_PARSER(resize, ResizeCmd::parse, void);
@@ -499,8 +537,8 @@ REGISTER_COMMAND_PARSER(resizeto, ResizeCmd::parse, void);
499REGISTER_COMMAND_PARSER(resizehorizontal, ResizeCmd::parse, void); 537REGISTER_COMMAND_PARSER(resizehorizontal, ResizeCmd::parse, void);
500REGISTER_COMMAND_PARSER(resizevertical, ResizeCmd::parse, void); 538REGISTER_COMMAND_PARSER(resizevertical, ResizeCmd::parse, void);
501 539
502ResizeCmd::ResizeCmd(const int step_size_x, const int step_size_y) : 540ResizeCmd::ResizeCmd(const int step_size_x, const int step_size_y, bool is_relative_x, bool is_relative_y) :
503 m_step_size_x(step_size_x), m_step_size_y(step_size_y) { } 541 m_step_size_x(step_size_x), m_step_size_y(step_size_y), m_is_relative_x(is_relative_x), m_is_relative_y(is_relative_y) { }
504 542
505void ResizeCmd::real_execute() { 543void ResizeCmd::real_execute() {
506 544
@@ -512,11 +550,27 @@ void ResizeCmd::real_execute() {
512 550
513 disableMaximizationIfNeeded(fbwindow()); 551 disableMaximizationIfNeeded(fbwindow());
514 552
515 int w = std::max<int>(static_cast<int>(fbwindow().width() + 553 int dx = m_step_size_x, dy = m_step_size_y;
516 m_step_size_x * fbwindow().winClient().widthInc()), 554 int windowWidth = fbwindow().width(), windowHeight = fbwindow().height();
555
556 unsigned int widthInc = fbwindow().winClient().widthInc(),
557 heightInc = fbwindow().winClient().heightInc();
558
559 if (m_is_relative_x) {
560 // dx = floor(windowWidth * m_step_size_x / 100 / widthInc + 0.5);
561 dx = static_cast<int>(FbTk::RelCalcHelper::calPercentageValueOf(windowWidth, m_step_size_x) / widthInc);
562 }
563
564 if (m_is_relative_y) {
565 // dy = floor(windowHeight * m_step_size_y / 100 / heightInc + 0.5);
566 dy = static_cast<int>(FbTk::RelCalcHelper::calPercentageValueOf(windowHeight, m_step_size_y) / heightInc);
567 }
568
569 int w = std::max<int>(static_cast<int>(windowWidth +
570 dx * widthInc),
517 fbwindow().frame().titlebarHeight() * 2 + 10); 571 fbwindow().frame().titlebarHeight() * 2 + 10);
518 int h = std::max<int>(static_cast<int>(fbwindow().height() + 572 int h = std::max<int>(static_cast<int>(windowHeight +
519 m_step_size_y * fbwindow().winClient().heightInc()), 573 dy * heightInc),
520 fbwindow().frame().titlebarHeight() + 10); 574 fbwindow().frame().titlebarHeight() + 10);
521 575
522 fbwindow().resize(w, h); 576 fbwindow().resize(w, h);
@@ -533,17 +587,10 @@ FbTk::Command<void> *MoveToCmd::parse(const string &cmd, const string &args,
533 587
534 FluxboxWindow::ReferenceCorner refc = FluxboxWindow::LEFTTOP; 588 FluxboxWindow::ReferenceCorner refc = FluxboxWindow::LEFTTOP;
535 int x = 0, y = 0; 589 int x = 0, y = 0;
536 bool ignore_x = false, ignore_y = false; 590 bool ignore_x = false, ignore_y = false, is_relative_x = false, is_relative_y = false;
537
538 if (tokens[0][0] == '*')
539 ignore_x = true;
540 else
541 x = atoi(tokens[0].c_str());
542 591
543 if (tokens[1][0] == '*' && !ignore_x) 592 parseToken(tokens[0], x, is_relative_x, ignore_x);
544 ignore_y = true; 593 parseToken(tokens[1], y, is_relative_y, ignore_y);
545 else
546 y = atoi(tokens[1].c_str());
547 594
548 if (tokens.size() >= 3) { 595 if (tokens.size() >= 3) {
549 refc = FluxboxWindow::getCorner(tokens[2]); 596 refc = FluxboxWindow::getCorner(tokens[2]);
@@ -551,7 +598,7 @@ FbTk::Command<void> *MoveToCmd::parse(const string &cmd, const string &args,
551 refc = FluxboxWindow::LEFTTOP; 598 refc = FluxboxWindow::LEFTTOP;
552 } 599 }
553 600
554 return new MoveToCmd(x, y, ignore_x, ignore_y, refc); 601 return new MoveToCmd(x, y, ignore_x, ignore_y, is_relative_x, is_relative_y, refc);
555} 602}
556 603
557REGISTER_COMMAND_PARSER(moveto, MoveToCmd::parse, void); 604REGISTER_COMMAND_PARSER(moveto, MoveToCmd::parse, void);
@@ -568,19 +615,31 @@ void MoveToCmd::real_execute() {
568 615
569 616
570 int x = m_pos_x, y = m_pos_y; 617 int x = m_pos_x, y = m_pos_y;
618 int head = fbwindow().getOnHead();
571 619
572 fbwindow().translateCoords(x, y, m_corner); 620 if (m_ignore_x) {
573 if (m_ignore_x)
574 x = fbwindow().x(); 621 x = fbwindow().x();
575 if (m_ignore_y) 622 } else {
623 if (m_is_relative_x) {
624 x = fbwindow().screen().calRelativeWidth(head, x);
625 }
626 fbwindow().translateXCoords(x, m_corner);
627 }
628 if (m_ignore_y) {
576 y = fbwindow().y(); 629 y = fbwindow().y();
630 } else {
631 if (m_is_relative_y) {
632 y = fbwindow().screen().calRelativeHeight(head, y);
633 }
634 fbwindow().translateYCoords(y, m_corner);
635 }
577 636
578 fbwindow().move(x, y); 637 fbwindow().move(x, y);
579} 638}
580 639
581 640
582ResizeToCmd::ResizeToCmd(const int step_size_x, const int step_size_y) : 641ResizeToCmd::ResizeToCmd(const int step_size_x, const int step_size_y, const bool is_relative_x, const bool is_relative_y) :
583 m_step_size_x(step_size_x), m_step_size_y(step_size_y) { } 642 m_step_size_x(step_size_x), m_step_size_y(step_size_y), m_is_relative_x(is_relative_x), m_is_relative_y(is_relative_y) { }
584 643
585void ResizeToCmd::real_execute() { 644void ResizeToCmd::real_execute() {
586 645
@@ -592,9 +651,31 @@ void ResizeToCmd::real_execute() {
592 651
593 disableMaximizationIfNeeded(fbwindow()); 652 disableMaximizationIfNeeded(fbwindow());
594 653
654 int dx = m_step_size_x, dy = m_step_size_y;
655 int head = fbwindow().getOnHead();
656
657 if (m_is_relative_x) {
658 dx = fbwindow().screen().calRelativeWidth(head, dx);
659 if(dx <= 0) {
660 dx = fbwindow().width();
661 }
662 }
663
664 if (m_is_relative_y) {
665 dy = fbwindow().screen().calRelativeHeight(head, dy);
666 if(dy <= 0) {
667 dy = fbwindow().height();
668 }
669 }
670
671 if (dx == 0) {
672 dx = fbwindow().width();
673 }
674 if (dy == 0) {
675 dy = fbwindow().height();
676 }
595 677
596 if (m_step_size_x > 0 && m_step_size_y > 0) 678 fbwindow().resize(dx, dy);
597 fbwindow().resize(m_step_size_x, m_step_size_y);
598} 679}
599 680
600REGISTER_COMMAND(fullscreen, FullscreenCmd, void); 681REGISTER_COMMAND(fullscreen, FullscreenCmd, void);
@@ -720,7 +801,7 @@ void SetAlphaCmd::real_execute() {
720 return; 801 return;
721 } 802 }
722 803
723 fbwindow().setFocusedAlpha(m_relative 804 fbwindow().setFocusedAlpha(m_relative
724 ? FbTk::Util::clamp(fbwindow().getFocusedAlpha() + m_focus, 0, 255) 805 ? FbTk::Util::clamp(fbwindow().getFocusedAlpha() + m_focus, 0, 255)
725 : m_focus); 806 : m_focus);
726 807