fluxbox/src/Workspace.cc

194 lines
5.2 KiB
C++
Raw Normal View History

2002-02-09 16:41:53 +00:00
// Workspace.cc for Fluxbox
// Copyright (c) 2001 - 2008 Henrik Kinnunen (fluxgen at fluxbox dot org)
2002-02-09 16:41:53 +00:00
//
2001-12-11 20:47:02 +00:00
// Workspace.cc for Blackbox - an X11 Window manager
2003-01-12 18:08:05 +00:00
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
2001-12-11 20:47:02 +00:00
//
// 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,
2003-01-12 18:08:05 +00:00
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2001-12-11 20:47:02 +00:00
// 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.
2002-08-11 22:35:40 +00:00
#include "Workspace.hh"
2001-12-11 20:47:02 +00:00
#include "Screen.hh"
#include "Window.hh"
2003-04-14 15:01:55 +00:00
#include "WinClient.hh"
2003-05-19 15:32:47 +00:00
#include "FbWinFrame.hh"
#include "FocusControl.hh"
#include "PlacementStrategy.hh"
2001-12-11 20:47:02 +00:00
2004-06-07 11:46:05 +00:00
#include "FbTk/I18n.hh"
#include "FbTk/StringUtil.hh"
#include "FbTk/FbString.hh"
#include "FbTk/MemFun.hh"
2002-08-11 22:35:40 +00:00
// use GNU extensions
2003-08-04 16:28:10 +00:00
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
2002-08-11 22:35:40 +00:00
#endif // _GNU_SOURCE
#ifdef HAVE_CONFIG_H
2002-10-13 21:52:00 +00:00
#include "config.h"
2002-08-11 22:35:40 +00:00
#endif // HAVE_CONFIG_H
2001-12-11 20:47:02 +00:00
2002-01-20 02:08:12 +00:00
#include <X11/Xlib.h>
#include <X11/Xatom.h>
2004-08-31 15:26:40 +00:00
#ifdef HAVE_CSTDIO
#include <cstdio>
#else
#include <stdio.h>
#endif
#ifdef HAVE_CSTRING
#include <cstring>
#else
#include <string.h>
#endif
2002-08-11 22:35:40 +00:00
2002-02-08 14:06:35 +00:00
#include <algorithm>
2002-08-11 22:35:40 +00:00
2006-10-30 19:31:15 +00:00
using std::string;
2007-10-13 21:51:37 +00:00
Workspace::Workspace(BScreen &scrn, const string &name, unsigned int id):
2003-05-11 15:35:03 +00:00
m_screen(scrn),
m_clientmenu(scrn, m_windowlist, false),
m_name(name),
m_id(id) {
2001-12-11 20:47:02 +00:00
m_clientlist_sig.connect(FbTk::MemFun(m_clientmenu,
&ClientMenu::refreshMenu));
2003-12-18 18:03:23 +00:00
menu().setInternalMenu();
setName(name);
2001-12-11 20:47:02 +00:00
}
2002-01-20 02:08:12 +00:00
Workspace::~Workspace() {
2001-12-11 20:47:02 +00:00
}
void Workspace::addWindow(FluxboxWindow &w) {
2003-04-14 15:01:55 +00:00
// we don't need to add a window that already exist in our list
2003-12-30 18:16:51 +00:00
if (find(m_windowlist.begin(), m_windowlist.end(), &w) != m_windowlist.end())
2003-06-24 14:57:54 +00:00
return;
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
w.setWorkspace(m_id);
m_windowlist.push_back(&w);
m_clientlist_sig.emit();
2001-12-11 20:47:02 +00:00
}
2004-03-21 09:00:25 +00:00
// still_alive is true if the window will continue to exist after
2006-10-30 19:31:15 +00:00
// this event. Particularly, this isn't the removeWindow for
2004-03-21 09:00:25 +00:00
// the destruction of the window. Because if so, the focus revert
// is done in another place
int Workspace::removeWindow(FluxboxWindow *w, bool still_alive) {
2003-04-14 15:01:55 +00:00
2002-12-01 13:42:15 +00:00
if (w == 0)
return -1;
2004-03-21 09:00:25 +00:00
if (w->isFocused() && still_alive)
FocusControl::unfocusWindow(w->winClient(), true, true);
2006-10-30 19:31:15 +00:00
2007-10-13 21:51:37 +00:00
m_windowlist.remove(w);
m_clientlist_sig.emit();
2002-12-01 13:42:15 +00:00
return m_windowlist.size();
2001-12-11 20:47:02 +00:00
}
2003-01-13 12:59:26 +00:00
void Workspace::showAll() {
Windows::iterator it = m_windowlist.begin();
Windows::iterator it_end = m_windowlist.end();
2003-08-24 11:19:45 +00:00
for (; it != it_end; ++it)
(*it)->show();
2001-12-11 20:47:02 +00:00
}
void Workspace::hideAll(bool interrupt_moving) {
Windows::reverse_iterator it = m_windowlist.rbegin();
Windows::reverse_iterator it_end = m_windowlist.rend();
2002-12-01 13:42:15 +00:00
for (; it != it_end; ++it) {
if (! (*it)->isStuck())
2007-10-13 21:51:37 +00:00
(*it)->hide(interrupt_moving);
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
2006-07-22 07:15:24 +00:00
void Workspace::removeAll(unsigned int dest) {
Windows tmp_list(m_windowlist);
Windows::iterator it = tmp_list.begin();
2007-10-24 19:38:27 +00:00
Windows::iterator it_end = tmp_list.end();
2003-08-24 11:19:45 +00:00
for (; it != it_end; ++it)
2006-07-22 07:15:24 +00:00
m_screen.sendToWorkspace(dest, *it, false);
2001-12-11 20:47:02 +00:00
}
2002-11-03 15:02:21 +00:00
void Workspace::reconfigure() {
2003-12-18 18:03:23 +00:00
menu().reconfigure();
2002-12-01 13:42:15 +00:00
Windows::iterator it = m_windowlist.begin();
Windows::iterator it_end = m_windowlist.end();
for (; it != it_end; ++it) {
if ((*it)->winClient().validateClient())
2002-12-01 13:42:15 +00:00
(*it)->reconfigure();
}
2001-12-11 20:47:02 +00:00
}
size_t Workspace::numberOfWindows() const {
2002-12-01 13:42:15 +00:00
return m_windowlist.size();
2001-12-11 20:47:02 +00:00
}
2006-10-30 19:31:15 +00:00
void Workspace::setName(const string &name) {
if (!name.empty() && name != "") {
if (name == m_name)
return;
2002-12-01 13:42:15 +00:00
m_name = name;
} else { //if name == 0 then set default name from nls
2004-06-07 11:46:05 +00:00
_FB_USES_NLS;
2002-12-01 13:42:15 +00:00
char tname[128];
2006-10-30 19:31:15 +00:00
sprintf(tname,
_FB_XTEXT(Workspace, DefaultNameFormat,
"Workspace %d", "Default workspace names, with a %d for the workspace number").c_str(),
2004-06-07 11:46:05 +00:00
m_id + 1); //m_id starts at 0
m_name = tname;
2002-12-01 13:42:15 +00:00
}
2006-10-30 19:31:15 +00:00
screen().updateWorkspaceName(m_id);
menu().setLabel(m_name);
menu().updateMenu();
2001-12-11 20:47:02 +00:00
}
2003-01-13 12:59:26 +00:00
/**
Calls restore on all windows
on the workspace and then
clears the m_windowlist
*/
void Workspace::shutdown() {
2002-12-01 13:42:15 +00:00
// note: when the window dies it'll remove it self from the list
while (!m_windowlist.empty()) {
2003-04-14 15:01:55 +00:00
//delete window (the window removes it self from m_windowlist)
2006-10-30 19:31:15 +00:00
delete m_windowlist.back();
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
}
void Workspace::updateClientmenu() {
m_clientlist_sig.emit();
}