aboutsummaryrefslogtreecommitdiff
path: root/src/WorkspaceCmd.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/WorkspaceCmd.cc')
-rw-r--r--src/WorkspaceCmd.cc158
1 files changed, 158 insertions, 0 deletions
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
new file mode 100644
index 0000000..f8f39da
--- /dev/null
+++ b/src/WorkspaceCmd.cc
@@ -0,0 +1,158 @@
1// WorkspaceCmd.cc for Fluxbox - an X11 Window manager
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen{<a*t>}users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
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:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
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.
22
23// $Id: WorkspaceCmd.cc,v 1.1 2003/06/30 14:38:42 fluxgen Exp $
24
25#include "WorkspaceCmd.hh"
26#include "Workspace.hh"
27#include "Window.hh"
28#include "Screen.hh"
29#include "fluxbox.hh"
30#include "Keys.hh"
31#include <algorithm>
32#include <functional>
33
34void NextWindowCmd::execute() {
35
36 BScreen *screen = Fluxbox::instance()->keyScreen();
37 if (screen != 0) {
38 Fluxbox *fb = Fluxbox::instance();
39 // special case for commands from key events
40 if (fb->lastEvent().type == KeyPress) {
41 unsigned int mods = Keys::cleanMods(fb->lastEvent().xkey.state);
42 if (mods == 0) // can't stacked cycle unless there is a mod to grab
43 screen->nextFocus(m_option | BScreen::CYCLELINEAR);
44 else {
45 // if stacked cycling, then set a watch for
46 // the release of exactly these modifiers
47 if (!fb->watchingScreen() && !(m_option & BScreen::CYCLELINEAR))
48 Fluxbox::instance()->watchKeyRelease(*screen, mods);
49 screen->nextFocus(m_option);
50 }
51 }
52
53 }
54}
55
56void PrevWindowCmd::execute() {
57 BScreen *screen = Fluxbox::instance()->keyScreen();
58 if (screen != 0) {
59 Fluxbox *fb = Fluxbox::instance();
60 // special case for commands from key events
61 if (fb->lastEvent().type == KeyPress) {
62 unsigned int mods = Keys::cleanMods(fb->lastEvent().xkey.state);
63 if (mods == 0) // can't stacked cycle unless there is a mod to grab
64 screen->prevFocus(m_option | BScreen::CYCLELINEAR);
65 else {
66 // if stacked cycling, then set a watch for
67 // the release of exactly these modifiers
68 if (!fb->watchingScreen() && !(m_option & BScreen::CYCLELINEAR))
69 Fluxbox::instance()->watchKeyRelease(*screen, mods);
70 screen->prevFocus(m_option);
71 }
72 }
73 }
74}
75
76void NextWorkspaceCmd::execute() {
77 BScreen *screen = Fluxbox::instance()->keyScreen();
78 if (screen != 0)
79 screen->nextWorkspace();
80}
81
82void PrevWorkspaceCmd::execute() {
83 BScreen *screen = Fluxbox::instance()->keyScreen();
84 if (screen != 0)
85 screen->prevWorkspace();
86}
87
88JumpToWorkspaceCmd::JumpToWorkspaceCmd(int workspace_num):m_workspace_num(workspace_num) { }
89
90void JumpToWorkspaceCmd::execute() {
91 BScreen *screen = Fluxbox::instance()->keyScreen();
92 if (screen != 0 && m_workspace_num >= 0 && m_workspace_num < screen->getNumberOfWorkspaces())
93 screen->changeWorkspaceID(m_workspace_num);
94}
95
96
97void ArrangeWindowsCmd::execute() {
98 BScreen *screen = Fluxbox::instance()->keyScreen();
99 if (screen == 0)
100 return;
101
102 Workspace *space = screen->currentWorkspace();
103 const unsigned int win_count = space->windowList().size();
104
105 if (win_count == 0)
106 return;
107
108 const unsigned int max_weigth = screen->width();
109 const unsigned int max_heigth = screen->height();
110
111
112 unsigned int cols = 1; // columns
113 unsigned int rows = 1; // rows
114
115 // Calculates the "best" width / heigth ratio ( basically it
116 // chooses the two divisors of win_count which are closest to
117 // each other)
118 int rt = win_count; // holds last t value
119 for (unsigned int i = 1; i <= win_count; ++i) {
120 int t = (win_count / i) - i;
121
122 if (t < rt && t >= 0 && (win_count % i) == 0) {
123 rt = t;
124 rows = i;
125 cols = win_count / i;
126 }
127 }
128
129 const unsigned int cal_width = max_weigth/cols; // calculated width ratio (width of every window)
130 const unsigned int cal_heigth = max_heigth/rows; // heigth ratio (heigth of every window)
131
132 // Resizes and sets windows positions in columns and rows.
133 unsigned int x_offs = 0; // window position offset in x
134 unsigned int y_offs = 0; // window position offset in y
135 unsigned int window = 0; // current window
136 Workspace::Windows &windowlist = space->windowList();
137 for (unsigned int i = 0; i < rows; ++i) {
138 x_offs = 0;
139 for (unsigned int j = 0; j < cols && window < win_count; ++j, ++window) {
140 windowlist[window]->moveResize(x_offs, y_offs, cal_width, cal_heigth);
141 // next x offset
142 x_offs += cal_width;
143 }
144 // next y offset
145 y_offs += cal_heigth;
146 }
147}
148
149void ShowDesktopCmd::execute() {
150 BScreen *screen = Fluxbox::instance()->keyScreen();
151 if (screen == 0)
152 return;
153
154 Workspace *space = screen->currentWorkspace();
155 std::for_each(space->windowList().begin(),
156 space->windowList().end(),
157 std::mem_fun(&FluxboxWindow::iconify));
158}