- * 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->set(getRootWindow(), otk::OBProperty::net_client_list,
- otk::OBProperty::Atom_Window, windows, windowList.size());
- delete [] windows;
- } else
- xatom->set(getRootWindow(), otk::OBProperty::net_client_list,
- otk::OBProperty::Atom_Window, 0, 0);
-
- updateStackingList();
-}
-
-
-/*
- * Set the _NET_CLIENT_LIST_STACKING root window property.
- */
-void BScreen::updateStackingList(void) {
-
- BlackboxWindowList stack_order;
-
- /*
- * Get the stacking 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(),
- end = stack_order.end();
- for (; it != end; ++it, ++win_it)
- *win_it = (*it)->getClientWindow();
- xatom->set(getRootWindow(), otk::OBProperty::net_client_list_stacking,
- otk::OBProperty::Atom_Window, windows, stack_order.size());
- delete [] windows;
- } else
- xatom->set(getRootWindow(), otk::OBProperty::net_client_list_stacking,
- otk::OBProperty::Atom_Window, 0, 0);
-}
-
-
-void BScreen::addSystrayWindow(Window window) {
- XGrabServer(otk::OBDisplay::display);
-
- XSelectInput(otk::OBDisplay::display, window, StructureNotifyMask);
- systrayWindowList.push_back(window);
- xatom->set(getRootWindow(), otk::OBProperty::kde_net_system_tray_windows,
- otk::OBProperty::Atom_Window,
- &systrayWindowList[0], systrayWindowList.size());
- blackbox->saveSystrayWindowSearch(window, this);
-
- XUngrabServer(otk::OBDisplay::display);
-}
-
-
-void BScreen::removeSystrayWindow(Window window) {
- XGrabServer(otk::OBDisplay::display);
-
- WindowList::iterator it = systrayWindowList.begin();
- const WindowList::iterator end = systrayWindowList.end();
- for (; it != end; ++it)
- if (*it == window) {
- systrayWindowList.erase(it);
- xatom->set(getRootWindow(),
- otk::OBProperty::kde_net_system_tray_windows,
- otk::OBProperty::Atom_Window,
- &systrayWindowList[0], systrayWindowList.size());
- blackbox->removeSystrayWindowSearch(window);
- XSelectInput(otk::OBDisplay::display, window, NoEventMask);
- break;
- }
-
- assert(it != end); // not a systray window
-
- XUngrabServer(otk::OBDisplay::display);
-}
-
-
-void BScreen::manageWindow(Window w) {
- // is the window a KDE systray window?
- Window systray;
- if (xatom->get(w, otk::OBProperty::kde_net_wm_system_tray_window_for,
- otk::OBProperty::Atom_Window, &systray) &&
- systray != None)
- {
- addSystrayWindow(w);
- return;
- }
-
- // is the window a docking app
- XWMHints *wmhint = XGetWMHints(otk::OBDisplay::display, w);
- if (wmhint && (wmhint->flags & StateHint) &&
- wmhint->initial_state == WithdrawnState) {
- //slit->addClient(w);
- return;
- }
-
- new BlackboxWindow(blackbox, w, this);
-
- BlackboxWindow *win = blackbox->searchWindow(w);
- if (! win)
- return;
-
- if (win->isDesktop()) {
- desktopWindowList.push_back(win->getFrameWindow());
- } else { // if (win->isNormal()) {
- // don't list desktop windows as managed windows
- windowList.push_back(win);
- updateClientList();
-
- if (win->isTopmost())
- specialWindowList.push_back(win->getFrameWindow());
- }
-
- XMapRequestEvent mre;
- mre.window = w;
- if (blackbox->state() == Openbox::State_Starting &&
- win->isNormal())
- win->restoreAttributes();
- win->mapRequestEvent(&mre);
-}
-
-
-void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
- // is the window a KDE systray window?
- Window systray;
- if (xatom->get(w->getClientWindow(),
- otk::OBProperty::kde_net_wm_system_tray_window_for,
- otk::OBProperty::Atom_Window, &systray) &&
- systray != None)
- {
- removeSystrayWindow(w->getClientWindow());
- return;
- }
-
- w->restore(remap);
-
- // Remove the modality so that its parent won't try to re-focus the window
- if (w->isModal()) w->setModal(False);
-
- if (w->getWorkspaceNumber() != BSENTINEL &&
- w->getWindowNumber() != BSENTINEL) {
- getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
- if (w->isStuck()) {
- for (unsigned int i = 0; i < getNumberOfWorkspaces(); ++i)
- if (i != w->getWorkspaceNumber())
- getWorkspace(i)->removeWindow(w, True);
- }
- } else if (w->isIconic())
- removeIcon(w);
-
- if (w->isDesktop()) {
- WindowList::iterator it = desktopWindowList.begin();
- const WindowList::iterator end = desktopWindowList.end();
- for (; it != end; ++it)
- if (*it == w->getFrameWindow()) {
- desktopWindowList.erase(it);
- break;
- }
- assert(it != end); // the window wasnt a desktop window?
- } else { // if (w->isNormal()) {
- // we don't list desktop windows as managed windows
- windowList.remove(w);
- updateClientList();
-
- if (w->isTopmost()) {
- WindowList::iterator it = specialWindowList.begin();
- const WindowList::iterator end = specialWindowList.end();
- for (; it != end; ++it)
- if (*it == w->getFrameWindow()) {
- specialWindowList.erase(it);
- break;
- }
- assert(it != end); // the window wasnt a special window?
- }
- }
-
- if (blackbox->getFocusedWindow() == w)
- blackbox->setFocusedWindow((BlackboxWindow *) 0);
-
- /*
- some managed windows can also be window group controllers. when
- unmanaging such windows, we should also delete the window group.
- */
- BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
- delete group;
-
- delete w;
-}
-
-
-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 otk::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->set(getRootWindow(), otk::OBProperty::net_workarea,
- otk::OBProperty::Atom_Cardinal,
- dims, 4 * workspacesList.size());
- delete [] dims;
- } else
- xatom->set(getRootWindow(), otk::OBProperty::net_workarea,
- otk::OBProperty::Atom_Cardinal, 0, 0);
-}
-
-
-void BScreen::updateNetizenWorkspaceCount(void) {
- xatom->set(getRootWindow(), otk::OBProperty::net_number_of_desktops,
- otk::OBProperty::Atom_Cardinal, workspacesList.size());
-
- updateWorkArea();
-}
-
-
-void BScreen::updateNetizenWindowFocus(void) {
- Window f = ((blackbox->getFocusedWindow()) ?
- blackbox->getFocusedWindow()->getClientWindow() : None);
-
- xatom->set(getRootWindow(), otk::OBProperty::net_active_window,
- otk::OBProperty::Atom_Window, f);
-}
-
-
-void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
- // the 13 represents the number of blackbox windows such as menus
- int bbwins = 15;
-#ifdef XINERAMA
- ++bbwins;
-#endif // XINERAMA
-
- Window *session_stack = new
- Window[(num + specialWindowList.size() + bbwins)];
- unsigned int i = 0, k = num;
-
- WindowList::iterator sit, send = specialWindowList.end();
- for (sit = specialWindowList.begin(); sit != send; ++sit)
- *(session_stack + i++) = *sit;
-
- while (k--)
- *(session_stack + i++) = *(workspace_stack + k);
-
- XRestackWindows(otk::OBDisplay::display, session_stack, i);
-
- delete [] session_stack;
-
- updateStackingList();
-}
-
-
-void BScreen::lowerWindows(Window *workspace_stack, unsigned int num) {
- assert(num > 0); // this would cause trouble in the XRaiseWindow call
-
- Window *session_stack = new Window[(num + desktopWindowList.size())];
- unsigned int i = 0, k = num;
-
- XLowerWindow(otk::OBDisplay::display, workspace_stack[0]);
-
- while (k--)
- *(session_stack + i++) = *(workspace_stack + k);
-
- WindowList::iterator dit = desktopWindowList.begin();
- const WindowList::iterator d_end = desktopWindowList.end();
- for (; dit != d_end; ++dit)
- *(session_stack + i++) = *dit;
-
- XRestackWindows(otk::OBDisplay::display, session_stack, i);
-
- delete [] session_stack;
-
- updateStackingList();
-}
-
-
-void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
- bool ignore_sticky) {
- if (! w) return;
-
- if (wkspc_id == BSENTINEL)
- wkspc_id = current_workspace->getID();
-
- if (w->getWorkspaceNumber() == wkspc_id)
- return;
-
- if (w->isIconic()) {
- removeIcon(w);
- getWorkspace(wkspc_id)->addWindow(w);
- if (w->isStuck())
- for (unsigned int i = 0; i < getNumberOfWorkspaces(); ++i)
- if (i != w->getWorkspaceNumber())
- getWorkspace(i)->addWindow(w, True);
- } else if (ignore_sticky || ! w->isStuck()) {
- if (w->isStuck())
- w->stick();
- getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
- getWorkspace(wkspc_id)->addWindow(w);
- }
- updateStackingList();
-}
-
-
-void BScreen::propagateWindowName(const BlackboxWindow *bw) {
- if (bw->isIconic()) {
- } else {
- }
-}
-
-
-void BScreen::nextFocus(void) const {
- BlackboxWindow *focused = blackbox->getFocusedWindow(),
- *next = focused;
-
- if (focused &&
- focused->getScreen()->getScreenNumber() == getScreenNumber() &&
- current_workspace->getCount() > 1) {
- do {
- next = current_workspace->getNextWindowInList(next);
- } while (next != focused && ! next->setInputFocus());
-
- if (next != focused)
- current_workspace->raiseWindow(next);
- } else if (current_workspace->getCount() > 0) {
- next = current_workspace->getTopWindowOnStack();
- next->setInputFocus();
- current_workspace->raiseWindow(next);
- }
-}
-
-
-void BScreen::prevFocus(void) const {
- BlackboxWindow *focused = blackbox->getFocusedWindow(),
- *next = focused;
-
- if (focused) {
- // if window is not on this screen, ignore it
- if (focused->getScreen()->getScreenNumber() != getScreenNumber())
- focused = (BlackboxWindow*) 0;
- }
-
- if (focused &&
- focused->getScreen()->getScreenNumber() == getScreenNumber() &&
- current_workspace->getCount() > 1) {
- // next is the next window to receive focus, current is a place holder
- do {
- next = current_workspace->getPrevWindowInList(next);
- } while (next != focused && ! next->setInputFocus());
-
- if (next != focused)
- current_workspace->raiseWindow(next);
- } else if (current_workspace->getCount() > 0) {
- next = current_workspace->getTopWindowOnStack();
- next->setInputFocus();
- current_workspace->raiseWindow(next);
- }
-}
-
-
-void BScreen::raiseFocus(void) const {
- BlackboxWindow *focused = blackbox->getFocusedWindow();
- if (! focused)
- return;
-
- // if on this Screen, raise it
- if (focused->getScreen()->getScreenNumber() == getScreenNumber()) {
- Workspace *workspace = getWorkspace(focused->getWorkspaceNumber());
- workspace->raiseWindow(focused);
- }
-}
-
-
-void BScreen::shutdown(void) {
- XSelectInput(otk::OBDisplay::display, getRootWindow(), NoEventMask);
- XSync(otk::OBDisplay::display, False);
-
- while(! windowList.empty())
- unmanageWindow(windowList.front(), True);
-
- while(! desktopWindowList.empty()) {
- BlackboxWindow *win = blackbox->searchWindow(desktopWindowList.front());
- assert(win);
- unmanageWindow(win, True);
- }
-}
-
-
-void BScreen::showPosition(int x, int y) {
- if (! geom_visible) {
- XMoveResizeWindow(otk::OBDisplay::display, geom_window,
- (getWidth() - geom_w) / 2,
- (getHeight() - geom_h) / 2, geom_w, geom_h);
- XMapWindow(otk::OBDisplay::display, geom_window);
- XRaiseWindow(otk::OBDisplay::display, geom_window);
-
- geom_visible = True;
- }
-
- char label[1024];
-
- sprintf(label, "X: %4d x Y: %4d", x, y);
-
- XClearWindow(otk::OBDisplay::display, geom_window);
-
- resource.wstyle.font->drawString(geom_window,
- resource.bevel_width, resource.bevel_width,
- resource.wstyle.l_text_focus,
- label);
-}
-
-
-void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
- if (! geom_visible) {
- XMoveResizeWindow(otk::OBDisplay::display, geom_window,
- (getWidth() - geom_w) / 2,
- (getHeight() - geom_h) / 2, geom_w, geom_h);
- XMapWindow(otk::OBDisplay::display, geom_window);
- XRaiseWindow(otk::OBDisplay::display, geom_window);
-
- geom_visible = True;
- }
-
- char label[1024];
-
- sprintf(label, "W: %4d x H: %4d", gx, gy);
-
- XClearWindow(otk::OBDisplay::display, geom_window);
-
- resource.wstyle.font->drawString(geom_window,
- resource.bevel_width, resource.bevel_width,
- resource.wstyle.l_text_focus,
- label);
-}
-
-
-void BScreen::hideGeometry(void) {
- if (geom_visible) {
- XUnmapWindow(otk::OBDisplay::display, geom_window);
- geom_visible = False;
- }
-}
-
-
-void BScreen::addStrut(Strut *strut) {
- strutList.push_back(strut);
-}
-
-
-void BScreen::removeStrut(Strut *strut) {
- strutList.remove(strut);
-}
-
-
-const otk::Rect& BScreen::availableArea(void) const {
- if (doFullMax())
- return getRect(); // return the full screen
- return usableArea;
-}
-
-
-#ifdef XINERAMA
-const RectList& BScreen::allAvailableAreas(void) const {
- assert(isXineramaActive());
- assert(xineramaUsableArea.size() > 0);
- fprintf(stderr, "1found x %d y %d w %d h %d\n",
- xineramaUsableArea[0].x(), xineramaUsableArea[0].y(),
- xineramaUsableArea[0].width(), xineramaUsableArea[0].height());
- return xineramaUsableArea;
-}
-#endif // XINERAMA
-
-
-void BScreen::updateAvailableArea(void) {
- otk::Rect old_area = usableArea;
- usableArea = getRect(); // reset to full screen
-