2003-06-30 14:38:42 +00:00
|
|
|
// WorkspaceCmd.cc for Fluxbox - an X11 Window manager
|
2005-01-24 18:34:57 +00:00
|
|
|
// Copyright (c) 2003 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
|
2003-06-30 14:38:42 +00:00
|
|
|
// and Simon Bowden (rathnor at users.sourceforge.net)
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2004-11-19 11:37:27 +00:00
|
|
|
// $Id$
|
2003-06-30 14:38:42 +00:00
|
|
|
|
|
|
|
#include "WorkspaceCmd.hh"
|
2003-09-06 14:05:32 +00:00
|
|
|
|
2003-06-30 14:38:42 +00:00
|
|
|
#include "Workspace.hh"
|
|
|
|
#include "Window.hh"
|
|
|
|
#include "Screen.hh"
|
|
|
|
#include "fluxbox.hh"
|
2004-04-28 14:59:12 +00:00
|
|
|
#include "WinClient.hh"
|
2003-09-06 14:05:32 +00:00
|
|
|
|
|
|
|
#include "FbTk/KeyUtil.hh"
|
|
|
|
|
2004-08-31 15:26:40 +00:00
|
|
|
#ifdef HAVE_CMATH
|
|
|
|
#include <cmath>
|
|
|
|
#else
|
|
|
|
#include <math.h>
|
|
|
|
#endif
|
2003-06-30 14:38:42 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
2003-12-30 18:16:51 +00:00
|
|
|
#include <iostream>
|
2003-06-30 14:38:42 +00:00
|
|
|
|
|
|
|
void NextWindowCmd::execute() {
|
|
|
|
|
|
|
|
BScreen *screen = Fluxbox::instance()->keyScreen();
|
|
|
|
if (screen != 0) {
|
|
|
|
Fluxbox *fb = Fluxbox::instance();
|
|
|
|
// special case for commands from key events
|
|
|
|
if (fb->lastEvent().type == KeyPress) {
|
2003-12-30 18:16:51 +00:00
|
|
|
unsigned int mods = FbTk::KeyUtil::instance().cleanMods(fb->lastEvent().xkey.state);
|
2003-06-30 14:38:42 +00:00
|
|
|
if (mods == 0) // can't stacked cycle unless there is a mod to grab
|
|
|
|
screen->nextFocus(m_option | BScreen::CYCLELINEAR);
|
|
|
|
else {
|
|
|
|
// if stacked cycling, then set a watch for
|
|
|
|
// the release of exactly these modifiers
|
2004-08-10 12:08:31 +00:00
|
|
|
if (!fb->watchingScreen() &&
|
|
|
|
!(m_option & BScreen::CYCLELINEAR))
|
2003-06-30 14:38:42 +00:00
|
|
|
Fluxbox::instance()->watchKeyRelease(*screen, mods);
|
|
|
|
screen->nextFocus(m_option);
|
|
|
|
}
|
2003-10-14 00:21:16 +00:00
|
|
|
} else
|
|
|
|
screen->nextFocus(m_option);
|
2003-06-30 14:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrevWindowCmd::execute() {
|
|
|
|
BScreen *screen = Fluxbox::instance()->keyScreen();
|
|
|
|
if (screen != 0) {
|
|
|
|
Fluxbox *fb = Fluxbox::instance();
|
|
|
|
// special case for commands from key events
|
|
|
|
if (fb->lastEvent().type == KeyPress) {
|
2003-12-30 18:16:51 +00:00
|
|
|
unsigned int mods = FbTk::KeyUtil::instance().cleanMods(fb->lastEvent().xkey.state);
|
2003-06-30 14:38:42 +00:00
|
|
|
if (mods == 0) // can't stacked cycle unless there is a mod to grab
|
|
|
|
screen->prevFocus(m_option | BScreen::CYCLELINEAR);
|
|
|
|
else {
|
|
|
|
// if stacked cycling, then set a watch for
|
|
|
|
// the release of exactly these modifiers
|
2004-08-10 12:08:31 +00:00
|
|
|
if (!fb->watchingScreen()
|
|
|
|
&& !(m_option & BScreen::CYCLELINEAR))
|
2003-06-30 14:38:42 +00:00
|
|
|
Fluxbox::instance()->watchKeyRelease(*screen, mods);
|
|
|
|
screen->prevFocus(m_option);
|
|
|
|
}
|
2003-10-14 00:21:16 +00:00
|
|
|
} else
|
|
|
|
screen->nextFocus(m_option);
|
2003-06-30 14:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-28 14:59:12 +00:00
|
|
|
void DirFocusCmd::execute() {
|
|
|
|
BScreen *screen = Fluxbox::instance()->keyScreen();
|
|
|
|
if (screen == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
WinClient *client = Fluxbox::instance()->getFocusedWindow();
|
|
|
|
if (client == 0 || client->fbwindow() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
screen->dirFocus(*client->fbwindow(), m_dir);
|
|
|
|
}
|
|
|
|
|
2003-06-30 14:38:42 +00:00
|
|
|
void NextWorkspaceCmd::execute() {
|
2003-07-19 13:51:24 +00:00
|
|
|
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
2003-06-30 14:38:42 +00:00
|
|
|
if (screen != 0)
|
|
|
|
screen->nextWorkspace();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrevWorkspaceCmd::execute() {
|
2003-07-19 13:51:24 +00:00
|
|
|
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
2003-06-30 14:38:42 +00:00
|
|
|
if (screen != 0)
|
|
|
|
screen->prevWorkspace();
|
|
|
|
}
|
|
|
|
|
2003-07-01 09:47:41 +00:00
|
|
|
void LeftWorkspaceCmd::execute() {
|
2003-07-19 13:51:24 +00:00
|
|
|
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
2003-07-01 09:47:41 +00:00
|
|
|
if (screen != 0)
|
|
|
|
screen->leftWorkspace(m_param);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RightWorkspaceCmd::execute() {
|
2003-07-19 13:51:24 +00:00
|
|
|
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
2003-07-01 09:47:41 +00:00
|
|
|
if (screen != 0)
|
|
|
|
screen->rightWorkspace(m_param);
|
|
|
|
}
|
|
|
|
|
2003-06-30 14:38:42 +00:00
|
|
|
JumpToWorkspaceCmd::JumpToWorkspaceCmd(int workspace_num):m_workspace_num(workspace_num) { }
|
|
|
|
|
|
|
|
void JumpToWorkspaceCmd::execute() {
|
2003-07-19 13:51:24 +00:00
|
|
|
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
2003-06-30 14:38:42 +00:00
|
|
|
if (screen != 0 && m_workspace_num >= 0 && m_workspace_num < screen->getNumberOfWorkspaces())
|
|
|
|
screen->changeWorkspaceID(m_workspace_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArrangeWindowsCmd::execute() {
|
2003-07-19 13:51:24 +00:00
|
|
|
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
2003-06-30 14:38:42 +00:00
|
|
|
if (screen == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Workspace *space = screen->currentWorkspace();
|
|
|
|
const unsigned int win_count = space->windowList().size();
|
|
|
|
|
|
|
|
if (win_count == 0)
|
|
|
|
return;
|
|
|
|
|
2004-01-16 09:21:31 +00:00
|
|
|
const int head = screen->getCurrHead();
|
|
|
|
const unsigned int max_width = screen->maxRight(head) - screen->maxLeft(head);
|
|
|
|
const unsigned int max_heigth = screen->maxBottom(head) - screen->maxTop(head);
|
2003-06-30 14:38:42 +00:00
|
|
|
|
2003-09-20 10:46:01 +00:00
|
|
|
// try to get the same number of rows as columns.
|
2004-08-10 12:08:31 +00:00
|
|
|
unsigned int rows = int(sqrt((float)win_count)); // truncate to lower
|
2003-09-20 10:46:01 +00:00
|
|
|
unsigned int cols = int(0.99 + float(win_count) / float(rows));
|
|
|
|
if (max_width<max_heigth) { // rotate
|
|
|
|
unsigned int tmp;
|
|
|
|
tmp = rows;
|
|
|
|
rows = cols;
|
|
|
|
cols = tmp;
|
|
|
|
}
|
|
|
|
const unsigned int cal_width = max_width/cols; // calculated width ratio (width of every window)
|
2003-06-30 14:38:42 +00:00
|
|
|
const unsigned int cal_heigth = max_heigth/rows; // heigth ratio (heigth of every window)
|
|
|
|
|
|
|
|
// Resizes and sets windows positions in columns and rows.
|
2005-04-21 09:05:02 +00:00
|
|
|
unsigned int x_offs = screen->maxLeft(head); // window position offset in x
|
|
|
|
unsigned int y_offs = screen->maxTop(head); // window position offset in y
|
2003-06-30 14:38:42 +00:00
|
|
|
unsigned int window = 0; // current window
|
|
|
|
Workspace::Windows &windowlist = space->windowList();
|
|
|
|
for (unsigned int i = 0; i < rows; ++i) {
|
2005-04-21 09:05:02 +00:00
|
|
|
x_offs = screen->maxLeft(head);
|
2003-06-30 14:38:42 +00:00
|
|
|
for (unsigned int j = 0; j < cols && window < win_count; ++j, ++window) {
|
2003-09-20 10:46:01 +00:00
|
|
|
if (window==(win_count-1)) {
|
|
|
|
// the last window gets everything that is left.
|
|
|
|
windowlist[window]->moveResize(x_offs, y_offs, max_width-x_offs, cal_heigth);
|
|
|
|
} else {
|
|
|
|
windowlist[window]->moveResize(x_offs, y_offs, cal_width, cal_heigth);
|
|
|
|
}
|
2003-06-30 14:38:42 +00:00
|
|
|
// next x offset
|
|
|
|
x_offs += cal_width;
|
|
|
|
}
|
|
|
|
// next y offset
|
|
|
|
y_offs += cal_heigth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowDesktopCmd::execute() {
|
2003-07-19 13:51:24 +00:00
|
|
|
BScreen *screen = Fluxbox::instance()->mouseScreen();
|
2003-06-30 14:38:42 +00:00
|
|
|
if (screen == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Workspace *space = screen->currentWorkspace();
|
|
|
|
std::for_each(space->windowList().begin(),
|
|
|
|
space->windowList().end(),
|
|
|
|
std::mem_fun(&FluxboxWindow::iconify));
|
|
|
|
}
|