2002-02-09 16:41:53 +00:00
|
|
|
// Workspace.cc for Fluxbox
|
2006-02-16 06:53:05 +00:00
|
|
|
// Copyright (c) 2001 - 2006 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.
|
|
|
|
|
2004-11-19 11:37:27 +00:00
|
|
|
// $Id$
|
2002-01-20 02:08:12 +00:00
|
|
|
|
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"
|
2006-02-18 20:19:22 +00:00
|
|
|
#include "FocusControl.hh"
|
2006-02-19 11:11:22 +00:00
|
|
|
#include "PlacementStrategy.hh"
|
2001-12-11 20:47:02 +00:00
|
|
|
|
2004-06-07 11:46:05 +00:00
|
|
|
#include "FbTk/I18n.hh"
|
2003-10-25 22:10:43 +00:00
|
|
|
#include "FbTk/StringUtil.hh"
|
2006-05-07 10:08:25 +00:00
|
|
|
#include "FbTk/FbString.hh"
|
2003-10-25 22:10:43 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-10-13 21:51:37 +00:00
|
|
|
#include <iostream>
|
2006-10-30 19:31:15 +00:00
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
|
|
|
#endif // DEBUG
|
2002-02-08 14:06:35 +00:00
|
|
|
|
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),
|
2007-10-13 21:51:37 +00:00
|
|
|
m_clientmenu(scrn, m_windowlist, &m_clientlist_sig),
|
2003-06-12 14:30:01 +00:00
|
|
|
m_name(name),
|
2003-12-14 01:10:39 +00:00
|
|
|
m_id(id) {
|
2001-12-11 20:47:02 +00:00
|
|
|
|
2003-12-18 18:03:23 +00:00
|
|
|
menu().setInternalMenu();
|
2003-07-25 10:03:55 +00:00
|
|
|
setName(name);
|
2006-02-19 11:11:22 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-10-24 17:09:26 +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);
|
2007-10-13 21:51:37 +00:00
|
|
|
m_clientlist_sig.notify();
|
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)
|
2006-02-18 20:19:22 +00:00
|
|
|
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.notify();
|
2003-04-16 14:43:06 +00:00
|
|
|
|
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() {
|
2003-02-02 16:32:41 +00:00
|
|
|
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)
|
2002-12-01 13:42:15 +00:00
|
|
|
(*it)->deiconify(false, false);
|
2001-12-11 20:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-13 01:48:18 +00:00
|
|
|
void Workspace::hideAll(bool interrupt_moving) {
|
2003-02-02 16:32:41 +00:00
|
|
|
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) {
|
2007-06-01 02:15:26 +00:00
|
|
|
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) {
|
2003-07-28 15:06:36 +00:00
|
|
|
if ((*it)->winClient().validateClient())
|
2002-12-01 13:42:15 +00:00
|
|
|
(*it)->reconfigure();
|
|
|
|
}
|
2001-12-11 20:47:02 +00:00
|
|
|
}
|
|
|
|
|
2006-04-02 21:37:44 +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) {
|
2005-04-27 09:52:30 +00:00
|
|
|
if (!name.empty() && name != "") {
|
2007-07-07 23:11:04 +00:00
|
|
|
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,
|
2006-05-20 15:08:14 +00:00
|
|
|
"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
|
2007-01-26 21:57:43 +00:00
|
|
|
m_name = tname;
|
2002-12-01 13:42:15 +00:00
|
|
|
}
|
2006-10-30 19:31:15 +00:00
|
|
|
|
2007-07-07 01:56:46 +00:00
|
|
|
screen().updateWorkspaceName(m_id);
|
2006-05-20 15:08:14 +00:00
|
|
|
|
|
|
|
menu().setLabel(m_name);
|
2004-12-13 14:03:17 +00:00
|
|
|
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
|
|
|
|
*/
|
2002-08-16 11:02:41 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-02-20 21:00:29 +00:00
|
|
|
void Workspace::updateClientmenu() {
|
2007-10-13 21:51:37 +00:00
|
|
|
m_clientlist_sig.notify();
|
2003-02-20 21:00:29 +00:00
|
|
|
}
|