aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLajos Koszti <ajnasz@ajnasz.hu>2012-04-06 12:10:24 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2012-04-06 12:11:16 (GMT)
commit7b6dc2ad72a4c4ecd20eddbfb6f1b4c3bd2a7024 (patch)
treec2a8f4aa658783c6454b7643ce2717acaa744101
parent5d56046b68635cea2c187e59a9d8c514e2d6bdb2 (diff)
downloadfluxbox-7b6dc2ad72a4c4ecd20eddbfb6f1b4c3bd2a7024.zip
fluxbox-7b6dc2ad72a4c4ecd20eddbfb6f1b4c3bd2a7024.tar.bz2
Allow percentage values for some Window commands
-rw-r--r--.gitignore8
-rw-r--r--doc/asciidoc/fluxbox-apps.txt9
-rw-r--r--doc/asciidoc/fluxbox-keys.txt27
-rw-r--r--src/CurrentWindowCmd.cc151
-rw-r--r--src/CurrentWindowCmd.hh20
-rw-r--r--src/FbTk/FbWindow.hh7
-rw-r--r--src/FbTk/Makefile.am1
-rw-r--r--src/FbTk/RelCalcHelper.cc38
-rw-r--r--src/FbTk/RelCalcHelper.hh43
-rw-r--r--src/Remember.cc104
-rw-r--r--src/Screen.cc49
-rw-r--r--src/Screen.hh17
-rw-r--r--src/Window.cc16
-rw-r--r--src/Window.hh2
-rw-r--r--src/tests/StringUtiltest.cc26
15 files changed, 416 insertions, 102 deletions
diff --git a/.gitignore b/.gitignore
index cf884c9..197941f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,5 +51,13 @@ util/startfluxbox
51version.h 51version.h
52install-sh 52install-sh
53missing 53missing
54src/tests/testFont
55src/tests/testFullscreen
56src/tests/testDemandAttention
57src/tests/testKeys
58src/tests/testRectangleUtil
59src/tests/testSignals
60src/tests/testStringUtil
61src/tests/testTexture
54*~ 62*~
55.*.swp 63.*.swp
diff --git a/doc/asciidoc/fluxbox-apps.txt b/doc/asciidoc/fluxbox-apps.txt
index 26f560b..07bac0e 100644
--- a/doc/asciidoc/fluxbox-apps.txt
+++ b/doc/asciidoc/fluxbox-apps.txt
@@ -114,14 +114,17 @@ respectively.
114 number. The named ones are: 2-AboveDock, 4-Dock, 6-Top, 8-Normal, 10-Bottom, 114 number. The named ones are: 2-AboveDock, 4-Dock, 6-Top, 8-Normal, 10-Bottom,
115 12-Desktop. 115 12-Desktop.
116 116
117*[Dimensions]* {'width' 'height'}:: 117*[Dimensions]* {'width[%]' 'height[%]'}::
118 Opens the application with the specified 'width' and 'height', in pixels. 118 Opens the application with the specified 'width' and 'height', in pixels.
119 If the value is given in percent, then the window size will be based on
120 the current screen's size.
119 121
120*[Position]* ('anchor') {'X' 'Y'}:: 122*[Position]* ('anchor') {'X[%]' 'Y[%]'}::
121Position the application at a particular spot. By default the upper-left corner 123Position the application at a particular spot. By default the upper-left corner
122is placed at screen coordinates ('X','Y'). If you specify an 'anchor', say 124is placed at screen coordinates ('X','Y'). If you specify an 'anchor', say
123BottomRight, then the lower-right corner of the window is positioned ('X','Y') 125BottomRight, then the lower-right corner of the window is positioned ('X','Y')
124pixels from the lower-right corner of the screen. 126pixels from the lower-right corner of the screen. If the value is given in
127percent, then the coordinates will be based on the current screen's size.
125+ 128+
126'anchor' may be set to one of:;; 129'anchor' may be set to one of:;;
127*TopLeft Left BottomLeft Top Center Bottom TopRight Right BottomRight* 130*TopLeft Left BottomLeft Top Center Bottom TopRight Right BottomRight*
diff --git a/doc/asciidoc/fluxbox-keys.txt b/doc/asciidoc/fluxbox-keys.txt
index 2679bc0..0d0b52e 100644
--- a/doc/asciidoc/fluxbox-keys.txt
+++ b/doc/asciidoc/fluxbox-keys.txt
@@ -259,17 +259,22 @@ These commands ordinarily affect only the currently focused window. The
259*DetachClient*:: 259*DetachClient*::
260 Remove the current tab from the tab group, placing it in its own window. 260 Remove the current tab from the tab group, placing it in its own window.
261 261
262*ResizeTo* 'width' 'height':: 262*ResizeTo* 'width[%]' 'height[%]'::
263 Resizes the window to the given width and height. 263 Resizes the window to the given width and height. If the value is given in
264 264 percent, then the window size will be based on the current screen's size.
265*Resize* 'delta-width' 'delta-height':: 265
266 Resizes the window relative to the current width and height. 266*Resize* 'delta-width[%]' 'delta-height[%]'::
267 267 Resizes the window relative to the current width and height. If the value
268*ResizeHorizontal* 'delta-width' / *ResizeVertical* 'delta-height':: 268 is given in percent, then the window size will be based on the current
269 Resizes the window in one dimension only 269 window's size.
270 270
271*MoveTo* 'x' 'y' ['anchor']:: 271*ResizeHorizontal* 'delta-width[%]' / *ResizeVertical* 'delta-height[%]'::
272Moves the window to the given coordinates, given in pixels. 272 Resizes the window in one dimension only. If the value is given in
273 percent, then the window size will be based on the current window's size.
274
275*MoveTo* 'x[%]' 'y[%]' ['anchor']::
276Moves the window to the given coordinates, given in pixels or relatively to
277the current screen size if % is specified after the value.
273+ 278+
274If either 'x' or 'y' is set to *\**, that coordinate will be ignored, and the 279If either 'x' or 'y' is set to *\**, that coordinate will be ignored, and the
275movement will only take place in one dimension. 280movement will only take place in one dimension.
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