// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
-#ifdef HAVE_CONFIG_H
-# include "../config.h"
-#endif // HAVE_CONFIG_H
+#include "../config.h"
extern "C" {
#include <X11/Xatom.h>
#endif // HAVE_STDARG_H
}
+#include <assert.h>
+
#include <algorithm>
#include <functional>
+#include <string>
using std::string;
#include "i18n.hh"
#include "Window.hh"
#include "Workspace.hh"
#include "Workspacemenu.hh"
+#include "XAtom.hh"
+#include "Input.hh"
#ifndef FONT_ELEMENT_SIZE
#define FONT_ELEMENT_SIZE 50
blackbox = bb;
screenstr = (string)"session.screen" + itostring(scrn) + '.';
config = blackbox->getConfig();
+ xatom = blackbox->getXAtom();
event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask;
resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
resource.wstyle.font = (XFontStruct *) 0;
+ xatom->setSupported(this); // set-up netwm support
#ifdef HAVE_GETPID
- pid_t bpid = getpid();
-
- XChangeProperty(blackbox->getXDisplay(), getRootWindow(),
- blackbox->getBlackboxPidAtom(), XA_CARDINAL,
- sizeof(pid_t) * 8, PropModeReplace,
- (unsigned char *) &bpid, 1);
+ xatom->setValue(getRootWindow(), XAtom::blackbox_pid, XAtom::cardinal,
+ (unsigned long) getpid());
#endif // HAVE_GETPID
+ unsigned long geometry[] = { getWidth(),
+ getHeight()};
+ xatom->setValue(getRootWindow(), XAtom::net_desktop_geometry,
+ XAtom::cardinal, geometry, 2);
+ unsigned long viewport[] = {0,0};
+ xatom->setValue(getRootWindow(), XAtom::net_desktop_viewport,
+ XAtom::cardinal, viewport, 2);
+
XDefineCursor(blackbox->getXDisplay(), getRootWindow(),
blackbox->getSessionCursor());
}
saveWorkspaceNames();
+ updateNetizenWorkspaceCount();
+
workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
workspacemenu->update();
current_workspace = workspacesList.front();
+
+ xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
+ XAtom::cardinal, 0); //first workspace
+
workspacemenu->setItemSelected(2, True);
toolbar = new Toolbar(this);
InitMenu();
- raiseWindows(0, 0);
+ raiseWindows(0, 0); // this also initializes the empty stacking list
rootmenu->update();
+ updateClientList(); // initialize the client list, which will be empty
updateAvailableArea();
changeWorkspaceID(0);
// call this again just in case a window we found updates the Strut list
updateAvailableArea();
+ updateFocusModel();
}
}
-void BScreen::removeWorkspaceNames(void) {
- workspaceNames.clear();
-}
-
void BScreen::saveSloppyFocus(bool s) {
resource.sloppy_focus = s;
}
+void BScreen::saveWindowToWindowSnap(bool s) {
+ resource.window_to_window_snap = s;
+ config->setValue(screenstr + "windowToWindowSnap",
+ resource.window_to_window_snap);
+}
+
+
+void BScreen::saveWindowCornerSnap(bool s) {
+ resource.window_corner_snap = s;
+ config->setValue(screenstr + "windowCornerSnap",
+ resource.window_corner_snap);
+}
+
+
void BScreen::saveWorkspaces(unsigned int w) {
resource.workspaces = w;
config->setValue(screenstr + "workspaces", resource.workspaces);
void BScreen::saveWorkspaceNames() {
+ XAtom::StringVect nameList;
+ unsigned long numnames = (unsigned) -1;
string names;
- WorkspaceList::iterator it;
- WorkspaceList::iterator last = workspacesList.end() - 1;
- for (it = workspacesList.begin(); it != workspacesList.end(); ++it) {
- names += (*it)->getName();
- if (it != last)
- names += ',';
+
+ if (numnames > 0 &&
+ xatom->getValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
+ numnames, nameList)) {
+ for (unsigned int i = 0; i < nameList.size(); ++i) {
+ if (i > 0) names += ",";
+ names += nameList[i];
+ }
}
config->setValue(screenstr + "workspaceNames", names);
}
saveFocusNew(resource.focus_new);
saveFocusLast(resource.focus_last);
saveHideToolbar(resource.hide_toolbar);
+ saveWindowToWindowSnap(resource.window_to_window_snap);
+ saveWindowCornerSnap(resource.window_corner_snap);
saveWorkspaces(resource.workspaces);
savePlacementPolicy(resource.placement_policy);
saveEdgeSnapThreshold(resource.edge_snap_threshold);
if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
resource.hide_toolbar = false;
+ if (! config->getValue(screenstr + "windowToWindowSnap",
+ resource.window_to_window_snap))
+ resource.window_to_window_snap = true;
+
+ if (! config->getValue(screenstr + "windowCornerSnap",
+ resource.window_corner_snap))
+ resource.window_corner_snap = true;
+
if (! config->getValue(screenstr + "imageDither", b))
b = true;
image_control->setDither(b);
else
resource.col_direction = TopBottom;
- removeWorkspaceNames();
+ XAtom::StringVect workspaceNames;
if (config->getValue(screenstr + "workspaceNames", s)) {
string::const_iterator it = s.begin(), end = s.end();
while(1) {
string::const_iterator tmp = it; // current string.begin()
it = std::find(tmp, end, ','); // look for comma between tmp and end
- addWorkspaceName(string(tmp, it)); // s[tmp:it]
+ workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
if (it == end)
break;
++it;
}
}
+ xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
+ workspaceNames);
resource.sloppy_focus = true;
resource.auto_raise = false;
workspacemenu->reconfigure();
iconmenu->reconfigure();
- int remember_sub = rootmenu->getCurrentSubmenu();
+ typedef std::vector<int> SubList;
+ SubList remember_subs;
+
+ // save the current open menus
+ Basemenu *menu = rootmenu;
+ int submenu;
+ while ((submenu = menu->getCurrentSubmenu()) >= 0) {
+ remember_subs.push_back(submenu);
+ menu = menu->find(submenu)->submenu();
+ assert(menu);
+ }
+
InitMenu();
raiseWindows(0, 0);
rootmenu->reconfigure();
- rootmenu->drawSubmenu(remember_sub);
+
+ // reopen the saved menus
+ menu = rootmenu;
+ const SubList::iterator subs_end = remember_subs.end();
+ for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
+ menu->drawSubmenu(*it);
+ menu = menu->find(*it)->submenu();
+ if (! menu)
+ break;
+ }
configmenu->reconfigure();
unsigned int BScreen::addWorkspace(void) {
Workspace *wkspc = new Workspace(this, workspacesList.size());
workspacesList.push_back(wkspc);
- saveWorkspaces(getWorkspaceCount() + 1);
- saveWorkspaceNames();
+ saveWorkspaces(getWorkspaceCount());
workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
wkspc->getID() + 2);
workspacesList.pop_back();
delete wkspc;
- saveWorkspaces(getWorkspaceCount() - 1);
- saveWorkspaceNames();
+ saveWorkspaces(getWorkspaceCount());
toolbar->reconfigure();
if (! current_workspace) return;
if (id != current_workspace->getID()) {
+ BlackboxWindow *focused = blackbox->getFocusedWindow();
+ if (focused && focused->getScreen() == this && ! focused->isStuck()) {
+ if (focused->getWorkspaceNumber() != current_workspace->getID()) {
+ fprintf(stderr, "%s is on the wrong workspace, aborting\n",
+ focused->getTitle());
+ abort();
+ }
+ current_workspace->setLastFocusedWindow(focused);
+ } else {
+ // if no window had focus, no need to store a last focus
+ current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
+ }
+ // when we switch workspaces, unfocus whatever was focused
+ blackbox->setFocusedWindow((BlackboxWindow *) 0);
+
current_workspace->hideAll();
-
workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
- if (blackbox->getFocusedWindow() &&
- blackbox->getFocusedWindow()->getScreen() == this &&
- (! blackbox->getFocusedWindow()->isStuck())) {
- current_workspace->setLastFocusedWindow(blackbox->getFocusedWindow());
- blackbox->setFocusedWindow((BlackboxWindow *) 0);
- }
-
current_workspace = getWorkspace(id);
+ xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
+ XAtom::cardinal, id);
+
workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
toolbar->redrawWorkspaceLabel(True);
}
+/*
+ * Set the _NET_CLIENT_LIST root window property.
+ */
+void BScreen::updateClientList(void) {
+ if (windowList.size() > 0) {
+ Window *windows = new Window[windowList.size()];
+ Window *win_it = windows;
+ BlackboxWindowList::iterator it = windowList.begin();
+ const BlackboxWindowList::iterator end = windowList.end();
+ for (; it != end; ++it, ++win_it)
+ *win_it = (*it)->getClientWindow();
+ xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
+ windows, windowList.size());
+ delete [] windows;
+ } else
+ xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
+ 0, 0);
+}
+
+
+/*
+ * Set the _NET_CLIENT_LIST_STACKING root window property.
+ */
+void BScreen::updateStackingList(void) {
+
+ BlackboxWindowList stack_order;
+
+ /*
+ * Get the atacking order from all of the workspaces.
+ * We start with the current workspace so that the sticky windows will be
+ * in the right order on the current workspace.
+ * XXX: Do we need to have sticky windows in the list once for each workspace?
+ */
+ getCurrentWorkspace()->appendStackOrder(stack_order);
+ for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
+ if (i != getCurrentWorkspaceID())
+ getWorkspace(i)->appendStackOrder(stack_order);
+
+ if (stack_order.size() > 0) {
+ // set the client list atoms
+ Window *windows = new Window[stack_order.size()];
+ Window *win_it = windows;
+ BlackboxWindowList::iterator it = stack_order.begin();
+ const BlackboxWindowList::iterator end = stack_order.end();
+ for (; it != end; ++it, ++win_it)
+ *win_it = (*it)->getClientWindow();
+ xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
+ XAtom::window, windows, stack_order.size());
+ delete [] windows;
+ } else
+ xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
+ XAtom::window, 0, 0);
+}
+
+
+void BScreen::addSystrayWindow(Window window) {
+ systrayWindowList.push_back(window);
+ xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
+ XAtom::window,
+ &systrayWindowList[0], systrayWindowList.size());
+ blackbox->saveSystrayWindowSearch(window, this);
+}
+
+
+void BScreen::removeSystrayWindow(Window window) {
+ WindowList::iterator it = systrayWindowList.begin();
+ const WindowList::iterator end = systrayWindowList.end();
+ for (; it != end; ++it)
+ if (*it == window) {
+ systrayWindowList.erase(it);
+ xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
+ XAtom::window,
+ &systrayWindowList[0], systrayWindowList.size());
+ blackbox->removeSystrayWindowSearch(window);
+ break;
+ }
+}
+
+
+void BScreen::addDesktopWindow(Window window) {
+ desktopWindowList.push_back(window);
+ XLowerWindow(blackbox->getXDisplay(), window);
+ XSelectInput(blackbox->getXDisplay(), window, StructureNotifyMask);
+ blackbox->saveDesktopWindowSearch(window, this);
+}
+
+
+void BScreen::removeDesktopWindow(Window window) {
+ WindowList::iterator it = desktopWindowList.begin();
+ const WindowList::iterator end = desktopWindowList.end();
+ for (; it != end; ++it)
+ if (*it == window) {
+ desktopWindowList.erase(it);
+ XSelectInput(blackbox->getXDisplay(), window, None);
+ blackbox->removeDesktopWindowSearch(window);
+ break;
+ }
+}
+
+
void BScreen::manageWindow(Window w) {
new BlackboxWindow(blackbox, w, this);
BlackboxWindow *win = blackbox->searchWindow(w);
if (! win)
return;
+ if (win->isDesktop()) {
+ // desktop windows cant do anything, so we remove all the normal window
+ // stuff from them, they are only kept around so that we can keep them on
+ // the bottom of the z-order
+ win->restore(True);
+ addDesktopWindow(win->getClientWindow());
+ delete win;
+ return;
+ }
windowList.push_back(win);
+ updateClientList();
XMapRequestEvent mre;
mre.window = w;
- win->restoreAttributes();
+ if (blackbox->isStartup()) win->restoreAttributes();
win->mapRequestEvent(&mre);
}
removeIcon(w);
windowList.remove(w);
+ updateClientList();
if (blackbox->getFocusedWindow() == w)
blackbox->setFocusedWindow((BlackboxWindow *) 0);
}
+void BScreen::updateWorkArea(void) {
+ if (workspacesList.size() > 0) {
+ unsigned long *dims = new unsigned long[4 * workspacesList.size()];
+ for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
+ // XXX: this could be different for each workspace
+ const Rect &area = availableArea();
+ dims[(i * 4) + 0] = area.x();
+ dims[(i * 4) + 1] = area.y();
+ dims[(i * 4) + 2] = area.width();
+ dims[(i * 4) + 3] = area.height();
+ }
+ xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
+ dims, 4 * workspacesList.size());
+ } else
+ xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
+ 0, 0);
+}
+
+
void BScreen::updateNetizenCurrentWorkspace(void) {
std::for_each(netizenList.begin(), netizenList.end(),
std::mem_fun(&Netizen::sendCurrentWorkspace));
void BScreen::updateNetizenWorkspaceCount(void) {
+ xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
+ XAtom::cardinal, workspacesList.size());
+
+ updateWorkArea();
+
std::for_each(netizenList.begin(), netizenList.end(),
std::mem_fun(&Netizen::sendWorkspaceCount));
}
void BScreen::updateNetizenWindowFocus(void) {
Window f = ((blackbox->getFocusedWindow()) ?
blackbox->getFocusedWindow()->getClientWindow() : None);
+
+ xatom->setValue(getRootWindow(), XAtom::net_active_window,
+ XAtom::window, f);
+
NetizenList::iterator it = netizenList.begin();
for (; it != netizenList.end(); ++it)
(*it)->sendWindowFocus(f);
void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
- // XXX: why 13??
+ // the 13 represents the number of blackbox windows such as menus
Window *session_stack = new
Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
unsigned int i = 0, k = num;
XRestackWindows(blackbox->getXDisplay(), session_stack, i);
delete [] session_stack;
-}
-
-void BScreen::addWorkspaceName(const string& name) {
- workspaceNames.push_back(name);
+ updateStackingList();
}
-/*
- * I would love to kill this function and the accompanying workspaceNames
- * list. However, we have a chicken and egg situation. The names are read
- * in during load_rc() which happens before the workspaces are created.
- * The current solution is to read the names into a list, then use the list
- * later for constructing the workspaces. It is only used during initial
- * BScreen creation.
- */
-const string BScreen::getNameOfWorkspace(unsigned int id) {
- if (id < workspaceNames.size())
- return workspaceNames[id];
- return string("");
+void BScreen::lowerDesktops(void) {
+ if (desktopWindowList.empty()) return;
+
+ XLowerWindow(blackbox->getXDisplay(), desktopWindowList[0]);
+ if (desktopWindowList.size() > 1)
+ XRestackWindows(blackbox->getXDisplay(), &desktopWindowList[0],
+ desktopWindowList.size());
}
for (; it != end; ++it)
if ((*it)->isMaximized()) (*it)->remaximize();
}
+
+ updateWorkArea();
}
if (model == SloppyFocus) {
saveSloppyFocus(True);
} else {
+ // we're cheating here to save writing the config file 3 times
+ resource.auto_raise = False;
+ resource.click_raise = False;
saveSloppyFocus(False);
- saveAutoRaise(False);
- saveClickRaise(False);
}
updateFocusModel();
void BScreen::updateFocusModel()
{
- std::for_each(workspacesList.begin(), workspacesList.end(),
- std::mem_fun(&Workspace::updateFocusModel));
+ std::for_each(iconList.begin(), iconList.end(),
+ std::mem_fun(&BlackboxWindow::ungrabButtons));
+ std::for_each(windowList.begin(), windowList.end(),
+ std::mem_fun(&BlackboxWindow::ungrabButtons));
+
+ if (! resource.sloppy_focus) {
+ blackbox->getInput()->add(Button1, 0, BInput::WindowClientPress,
+ BInput::Raise);
+ blackbox->getInput()->add(Button1, 0, BInput::WindowClientPress,
+ BInput::Focus);
+ } else {
+ if (resource.click_raise)
+ blackbox->getInput()->add(Button1, 0, BInput::WindowClientPress,
+ BInput::Raise);
+ else
+ blackbox->getInput()->remove(Button1, 0, BInput::WindowClientPress,
+ BInput::Raise);
+ blackbox->getInput()->remove(Button1, 0, BInput::WindowClientPress,
+ BInput::Focus);
+ }
+
+ std::for_each(iconList.begin(), iconList.end(),
+ std::mem_fun(&BlackboxWindow::grabButtons));
+ std::for_each(windowList.begin(), windowList.end(),
+ std::mem_fun(&BlackboxWindow::grabButtons));
}